Jump to content


Photo
- - - - -

getting this script to work in cron


  • Please log in to reply
2 replies to this topic

#1 zandi

zandi

    SUP3R 31337 P1MP

  • Members
  • 263 posts
  • Location:michigan

Posted 23 February 2010 - 10:25 PM

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?

#2 SigFLUP

SigFLUP

    SUPR3M3 31337 Mack Daddy P1MP

  • Members
  • 367 posts
  • Gender:Not Telling

Posted 25 February 2010 - 12:06 PM

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.

#3 LexDysic

LexDysic

    DDP Fan club member

  • Members
  • 57 posts

Posted 20 May 2010 - 03:32 AM

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




BinRev is hosted by the great people at Lunarpages!