Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hey guys. I wrote a small bash script to use feh to change my background every time its called. I use a cron job to have it execute every 5 minutes.
When I run the script manually it works perfectly, however for some reason when its run via cron it fails. I can see that it is executing but it seems to error for some reason.
Any reason why this would happen? Its kind of a drag to have a working script that when run as a cron job suddenly no longer works.
Cron jobs have their own limited environment and their rules. It's difficult to give a clue without seeing the crontab entry and/or the content of the script. By the way, as a normal behavior, the cron daemon sends standard output and standard error of jobs to the crontab owner's mailbox (if they are not explicitly redirected to a file). Have you checked it?
Aug 21 18:04:01 drone_x61 cron[3818]: (alphis) RELOAD (crontabs/rage)
Aug 21 18:05:01 drone_x61 cron[19512]: (alphis) CMD (rotate_wallpapers.sh)
Aug 21 18:05:22 drone_x61 cron[19511]: (alphis) MAIL (mailed 49 bytes of output but got status 0x0001
this is a piece of the output from /var/log/messages
It might work. Cron is not aware of X, it run in a deeper layer and does not know about higher layers. The DISPLAY variable -may- point feh to the right place, or not.
Ok I redirected output (why didn't I do this before) to a file.
feh ERROR: Can't open X display. It *is* running, yeah?
feh ERROR: Can't open X display. It *is* running, yeah?
So....I take it cron cannot access my X session? Is there anyway to get around this? I'm beginning to think I'll have to just write the script and have it running in the background constantly if cron cannot do this job.
You can try the hint given by Elv13 above. Regarding the mailbox, do you mean the mail command does not exist on your system and you cannot receive system mail?
Ok I redirected output (why didn't I do this before) to a file.
feh ERROR: Can't open X display. It *is* running, yeah?
feh ERROR: Can't open X display. It *is* running, yeah?
So....I take it cron cannot access my X session? Is there anyway to get around this? I'm beginning to think I'll have to just write the script and have it running in the background constantly if cron cannot do this job.
Any thoughts?
Have you added DISPLAY=:0 as I said? If it can not redirect from there, then you will have to run the script from X. All WMs have autorun capabilities in a way or an other.
#echo "MAX: $MAX"
INDEX=$RANDOM
let "INDEX %= $MAX"
#echo "INDEX: $INDEX"
for i in `ls /home/rage/wallpapers | grep -v \.sh`;
do
if [ $COUNTER -eq $INDEX ]; then
#echo "switching to $i"
DISPLAY=:0 feh --bg-scale /home/rage/wallpapers/$i &
break
fi
let COUNTER+=1
done
Thanks again for all your help! =]
Edit:
to answer your question regarding mail, yes mail is not in my path. I checked dead.letter and got the output /var/log/messages was referring to
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.