LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 08-21-2010, 05:49 PM   #1
alphisb0t
Member
 
Registered: Jun 2004
Distribution: gentoo 2008.desktop
Posts: 110

Rep: Reputation: 15
cronjob + feh


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.

Thanks.
 
Old 08-21-2010, 05:56 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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?

Last edited by colucix; 08-21-2010 at 05:58 PM.
 
Old 08-21-2010, 06:02 PM   #3
alphisb0t
Member
 
Registered: Jun 2004
Distribution: gentoo 2008.desktop
Posts: 110

Original Poster
Rep: Reputation: 15
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

As for mail, I don't even have a mailbox setup.

Any ideas?
 
Old 08-21-2010, 06:04 PM   #4
Elv13
Member
 
Registered: Apr 2006
Location: Montreal,Quebec
Distribution: Gentoo
Posts: 825

Rep: Reputation: 129Reputation: 129
Add DISPLAY=:0 before feh
Code:
DISPLAY=:0 few --bg-scale /path/to/image.png
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.
 
Old 08-21-2010, 06:05 PM   #5
alphisb0t
Member
 
Registered: Jun 2004
Distribution: gentoo 2008.desktop
Posts: 110

Original Poster
Rep: Reputation: 15
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?
 
Old 08-21-2010, 06:10 PM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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?
 
Old 08-21-2010, 06:22 PM   #7
Elv13
Member
 
Registered: Apr 2006
Location: Montreal,Quebec
Distribution: Gentoo
Posts: 825

Rep: Reputation: 129Reputation: 129
Quote:
Originally Posted by alphisb0t View Post
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.

The script can look like
Code:
#!/bin/bash
{
while true;do
  feh ... <your wallpaper>
  sleep 15m
done
} &
Will will run every 15 minutes
 
Old 08-21-2010, 06:25 PM   #8
alphisb0t
Member
 
Registered: Jun 2004
Distribution: gentoo 2008.desktop
Posts: 110

Original Poster
Rep: Reputation: 15
Adding DISPLAY=:0 before feh was just what I needed! Works perfectly now!

Thanks much.

If anyone is interested in the BASH script I made for this here it is:

Quote:
#!/bin/bash

MAX=`ls /home/rage/wallpapers | grep -v \.sh | wc -l`
COUNTER=0

#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

Last edited by alphisb0t; 08-21-2010 at 06:30 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Problem installing feh cola Slackware 4 12-19-2009 01:46 AM
feh problems Th3_J3st3R Slackware 12 06-08-2009 01:44 AM
installing FEH on DSL Daravon Linux - Software 1 08-14-2008 02:16 AM
fbsetbg and feh soldan Linux - Newbie 3 11-27-2006 06:20 AM
How do I switch from Esetroot to feh??? Southpaw76 Linux - Software 3 12-13-2005 06:14 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration