Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Cron and shell problem
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
crowbar
n00b
n00b


Joined: 03 Jan 2003
Posts: 20

PostPosted: Sun Feb 23, 2003 9:19 pm    Post subject: Cron and shell problem Reply with quote

I wrote this little script to randomly pick and change the background image in XFCE:
Code:

#!/bin/bash
number=$(head -1 /dev/urandom | od -N 1 | awk '{ print $2 }')
let "number %= `wc -l /home/bob/.desk_images | awk '{print $1}'`"
sed "$number!d" /home/bob/.desk_images>/home/bob/.xfce/xfbdrc
echo "auto">>/home/bob/.xfce/xfbdrc
xfbd
exit 0

It runs fine if run from the command line, but if run as acron job, xbfb (the backdrop manager) doesn't execute (and/or read the rc file).
I've tried adding exec xfbd as well.
The only thing I can think of is that running as a cron job is messing up the user?

Rob
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 20054

PostPosted: Sun Feb 23, 2003 9:27 pm    Post subject: Reply with quote

Have you tried using the full path to xfbd?
_________________
Quis separabit? Quo animo?
Back to top
View user's profile Send private message
slartibartfasz
Veteran
Veteran


Joined: 29 Oct 2002
Posts: 1462
Location: Vienna, Austria

PostPosted: Mon Feb 24, 2003 5:00 pm    Post subject: Reply with quote

check if u specified SHELL in the crontab and keep in mind that as a cronjob your script has not your users shell environment - better always use absolute paths for this...
_________________
To an engineer the glass is neither half full, nor half empty - it is just twice as big as it needs to be.
Back to top
View user's profile Send private message
crowbar
n00b
n00b


Joined: 03 Jan 2003
Posts: 20

PostPosted: Mon Feb 24, 2003 9:07 pm    Post subject: Reply with quote

I did try (after posting) using the full path (though it is on the cron path /usr/bin/).
It apparently is a Gtk error:
Quote:

Gtk-WARNING **: cannot open display:

Good thing I get all mail to root sent to a real person :D
Back to top
View user's profile Send private message
crowbar
n00b
n00b


Joined: 03 Jan 2003
Posts: 20

PostPosted: Wed Feb 26, 2003 8:30 pm    Post subject: Solution Reply with quote

It may not be the most elegant but:
Code:

#!/bin/bash
number=0
while test "$DISPLAY" != ""
do
 while test $number -lt 1
 do
  #generate a random number
  number=$(head -1 /dev/urandom | od -N 1 | awk '{ print $2 }')
  #rescale to the number of lines in the file
  let "number %= `wc -l /home/bob/.desk_images | awk '{print $1}'`"
 done
 sed "$number!d" /home/bob/.desk_images>/home/bob/.xfce/xfbdrc
 echo "auto">>/home/bob/.xfce/xfbdrc
 /usr/bin/xfbd
 $number
 number=0
 sleep 1h
done
exit 0


It works :)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum