Sign in to follow this  
Followers 0
zandi

getting this script to work in cron

3 posts in this topic

at the moment i'm trying to automatically cycle through images to use as my background, and i've found a script that does this. the script works fine when i run it manually through the terminal, but never seems to work when cron runs it. i can tell from syslog that cron is running the script, and it doesn't seem like the script is running differently at all from stdout and sterr (i have them piped to a text file) but my background image doesn't change.

i'm not sure how else to describe it, so here's the script, permissions, and crontab

script

#!/bin/bash

# Script to randomly set Background from files in a directory

#hopefully set some of the environment variables properly...
#/home/zandi/.profile

# Directory Containing Pictures
DIR="/home/zandi/Pictures/space"
#DISPLAY=:0.0
#USER=zandi
#USERNAME=zandi

# Command to Select a random jpg file from directory
# Delete the *.jpg to select any file but it may return a folder
PIC=$(ls $DIR/*.jpg | shuf -n1)

#set the wallpaper
/usr/bin/gconftool -t string -s /desktop/gnome/background/picture_filename $PIC

permissions

-rwsr-xr-x 1 zandi zandi      519 2010-02-23 21:23 wallpaper.sh

crontab

* * * * * /home/zandi/wallpaper.sh >/tmp/cron.log 2&>1

stdout and stderr is getting piped to /tmp/cron.log, i just didn't show the file here because it's blank.

any ideas as to why this isn't working?

0

Share this post


Link to post
Share on other sites

Perhaps you should un-comment DISPLAY=:0.0 and make sure that you have the -ac argument in your /etc/X11/xinit/xserverrc or /etc/X11/xdm/Xservers file.

0

Share this post


Link to post
Share on other sites

Perhaps you should un-comment DISPLAY=:0.0 and make sure that you have the -ac argument in your /etc/X11/xinit/xserverrc or /etc/X11/xdm/Xservers file.

Ya, just a FYI: cron does not take in your environmental vars. So you'll have to set them yourself. (including DISPLAY)

Also I noticed this:

#hopefully set some of the environment variables properly...

#/home/zandi/.profile

To parse that file you will need to change it to (note the space):

. /home/zandi/.profile

OR

source /home/zandi/.profile

~good luck

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0