[Cialug] cron/bash

Josh More MoreJ at alliancetechnologies.net
Thu Oct 21 17:20:58 CDT 2010


If this bit:  "% xhost +  \n  will open your X session so that anyone can run anything on it."  worries you, it should.  xhost is an IP level of security... and should be only needed if you are running interactive GUI stuff.

If you have a permissions error, it's likely a user thing, and you should make sure that your cron job is running under your "chris" user.

Most likely, though, is that it's an environment problem.  That's very common in cron as cron does not load the user environment before it runs things.

Hey look, as I was writing this, Zach said what I was going to.  Compare your environment variables between an active shell and a cron shell  (printenv > /tmp/cronenv.txt) and see what's missing.

-Josh More, CISSP, GIAC-GSLC, GIAC-GCIH, RHCE, NCLP
morej at alliancetechnologies.net<mailto:morej at alliancetechnologies.net>
515-245-7701
________________________________
From: cialug-bounces at cialug.org [cialug-bounces at cialug.org] on behalf of Joseph Pietras [joseph.pietras at gmail.com]
Sent: Thursday, October 21, 2010 17:21
To: Central Iowa Linux Users Group
Subject: Re: [Cialug] cron/bash

When you run it on desktop it should have permissions to change the desktop.  But when as a bash script it might not - and I presume so.

% xhost +
will open your X session so that anyone can run anything on it.

If that works you can change "xhost +" to "xhost +<whatever>", I can't recall the syntax.
HTH
-joseph

On Thu, Oct 21, 2010 at 5:16 PM, chris <c.rheinherren at gmail.com<mailto:c.rheinherren at gmail.com>> wrote:
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


_______________________________________________
Cialug mailing list
Cialug at cialug.org<mailto:Cialug at cialug.org>
http://cialug.org/mailman/listinfo/cialug




--
-Joseph
cell 858-337-9922
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://cialug.org/pipermail/cialug/attachments/20101021/c6220513/attachment.htm 


More information about the Cialug mailing list