You are not logged in.

#1 2008-09-03 21:31:57

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

[Solved]Cron - feh wallpaper changer

I tried the following script from the feh wiki page to change my wallpaper:

#!/bin/sh
WALLPAPERS="/mnt/path/to/wallpapers"
ALIST=( `ls -w1 $WALLPAPERS` )
RANGE=${#ALIST[*]}
SHOW=$(( $RANDOM % $RANGE ))
feh --bg-scale $WALLPAPERS/${ALIST[$SHOW]}

Here's the cron job (trying to run it every two minutes)

*/2 * * * * /usr/local/bin/wallpaper.sh

Why doesn't it work from cron? If I run the script from the command line, it works fine.

Any ideas?

Thanks, Scott

Last edited by firecat53 (2008-09-04 00:10:44)

Offline

#2 2008-09-03 21:34:34

haxit
Member
From: /home/haxit
Registered: 2008-03-04
Posts: 1,247
Website

Re: [Solved]Cron - feh wallpaper changer

I don't think cron can run something every two minutes. Only 1minute, 1hour, and 1 day intervals along with its other features, if I am not mistaken.


Archi686 User | Old Screenshots | Old .Configs
Vi veri universum vivus vici.

Offline

#3 2008-09-03 21:44:00

genisis300
Member
From: Uk
Registered: 2008-01-15
Posts: 284

Re: [Solved]Cron - feh wallpaper changer

the other problem is cron runs as root and it can't access your display try su your username in the script

Last edited by genisis300 (2008-09-03 21:44:30)


"is adult entertainment killing our children or is killing our children entertaining adults?" Marilyn Manson

Offline

#4 2008-09-03 22:05:45

finferflu
Forum Fellow
From: Manchester, UK
Registered: 2007-06-21
Posts: 1,899
Website

Re: [Solved]Cron - feh wallpaper changer

You can actually run cron every two minutes, and you cron command seems to be fine. I believe your issue has more to do with what genesis300 has pointed out.


Have you Syued today?
Free music for free people! | Earthlings

"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- A. de Saint-Exupery

Offline

#5 2008-09-03 22:29:18

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: [Solved]Cron - feh wallpaper changer

Ok, I changed the script with su, but it's still not working. As an idiot check, I looked, and the cron deamon is indeed running smile

If I try to run the script from the command line now, it asks me for my user password . . . and I'm already running as that user.
I tried a test cron :
*/1 * * * * /bin/date >> /home/firecat53/date.txt

And it worked fine. The permissions on date.txt were firecat53:users 644. So doesn't that mean that that cronjob is executed as me? If I edited crontab like
sudo crontab -e
then I think it would create a job as the root user.

Could this have something to do with somehow needing to recognize a running X session, since feh is an X application?

#!/bin/sh
WALLPAPERS="/mnt/ubuntu-home/firecat53/docs/wallpapers"
ALIST=( `ls -w1 $WALLPAPERS` )
RANGE=${#ALIST[*]}
SHOW=$(( $RANDOM % $RANGE ))
su -c 'feh --bg-scale $WALLPAPERS/${ALIST[$SHOW]}' firecat53

I'm afraid I'm still stumped!

Thanks!
Scott

Last edited by firecat53 (2008-09-03 22:40:35)

Offline

#6 2008-09-04 00:07:55

nj
Member
Registered: 2007-04-06
Posts: 93

Re: [Solved]Cron - feh wallpaper changer

Open up an xterm and run 'env | grep -i display'. The output will probably be :0.0. Add it to your shell script like so:

DISPLAY=:0.0 feh --bg-scale $WALLPAPERS/${ALIST[$SHOW]}

There should be no need use sudo while creating the crontab or while in the script.

Offline

#7 2008-09-04 00:10:16

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: [Solved]Cron - feh wallpaper changer

Yep, I just found the DISPLAY=:0.0 trick just before you posted, nj smile  So I took out the su from the script and it works perfectly with the cronjob as follows:

*/2 * * * * DISPLAY=:0.0 /usr/local/bin/wallpaper.sh

Thanks, all!
Scott

Offline

Board footer

Powered by FluxBB