[Cialug] cron/bash

chris c.rheinherren at gmail.com
Thu Oct 21 17:16:36 CDT 2010


I'm attempting to have a bash script setup to run as a cronjob but it
doesnt.

Here are the details:
*/2 * * * * /home/chris/scripts/crotate.sh
This is the original bash script, I didn't write it but I like it.

#!/bin/bash

#
# Rotates GNOME Wallpaper using pictures in $FOLDER
# Run in background: ./rotate.sh &
# Make sure there are no spaces in picture filenames
# http://ubuntu.online02.com/node/37
#

FOLDER="/home/chris/Pictures/Wallpapers/current" # Change to your directory
cd $FOLDER

loop () {
NUMBER=$(ls -1 | wc -l)
RAN=$(($RANDOM%$NUMBER+1))
FILE=$(ls -1 | sed -n ${RAN}p)
echo $FILE
gconftool-2 --set "/desktop/gnome/background/picture_filename" --type string
"$FOLDER/$FILE"
sleep 90 # Time between change
loop
}
loop


-------------------

it works fine if you just run it or put it in screen and run it so you can
detach and close out of it while it runs.
So I wanted to run this without having a screen or open terminal session
going so I removed the loop notes and setup a cron job for it.


This is the modified script.

#!/bin/bash

FOLDER="/home/chris/Pictures/Wallpapers/current" # Change to your directory
cd $FOLDER

NUMBER=$(ls -1 | wc -l)
RAN=$(($RANDOM%$NUMBER+1))
FILE=$(ls -1 | sed -n ${RAN}p)
echo $FILE >> /home/chris/scripts/wallpaper.log
/usr/bin/gconftool-2 --set "/desktop/gnome/background/picture_filename"
--type string "$FOLDER/$FILE"


It does write to my log file that i created. Just fine with the name of the
image that should be the desktop image but there is no change to the
desktop.


# m h  dom mon dow   command
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
*/2 * * * * /home/chris/scripts/crotate.sh

------------------


Any help would be great.

Just calling the script ./crotate.sh and it works fine.

Thanks.


Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://cialug.org/pipermail/cialug/attachments/20101021/79393a79/attachment.htm 


More information about the Cialug mailing list