Click to See Complete Forum and Search --> : Script Wont work from crontab


glow_worm
01-15-2003, 12:58 AM
OK..heres the deal ..

script:

#!/bin/sh

PIDS=$(/bin/more /tmp/ices.pid)
ARTIST=$( /bin/cat -n /tmp/ices.cue.$PIDS | /bin/grep "^ 7" | /bin/cut -f2- | /bin/awk '{print $0}' )
TITLE=$( /usr/bin/tail -n 1 /tmp/ices.cue.$PIDS )
/bin/rm -rf /home/off/egg6/scripts/shout.out
/bin/echo whooradio shoutcast @ http://www.owenmeany.com:8080 is playing: $ARTIST - $TITLE > /home/off/egg6/scripts/shout.out

--

It works fine from a prompt. The permissions are correct. When run from a crontab the entry echo'd to /home/off/egg6/scripts/shout.out is:
hooradio shoutcast @ http://www.owenmeany.com:8080 is playing: - ==> /tmp/ices.pid <== 17217


I have tried setting a path variable within the script. doesnt work, you can see I am already using full paths for the bins.. I am at a loss, any ideas?

tia, glow_worm

PS: I have tried running the script in roots crontab, doesnt work, and Ive tried a regualr user..it doesnt matter..same output.

hotleadpdx
01-19-2003, 01:55 PM
You need to wrap your script in a logging script to see what's happening when it tries to run via crontab.

To do this, add set -x to the first line of your shell script. Then add the entry in the crontab calling the script, at the end redirect the output to a log file.

ex.

5 * * * * /usr/bin/myscript.sh > /var/log/myscript.log 2>&1

When run a log will be created in the /var/log directory called 'myscript.log.' With the set -x at the beginning of the script, all commands will be echoed to STDOUT and captured in the log file. The 2>&1 captures errors which should allow you to see why the script won't run in the crontab.

glow_worm
01-19-2003, 02:04 PM
yeah, i had already added set -x to it, i just omitted it here since it wasnt integral to the actual script operation, however your other advice helps me immensely with something else.

The script is question is fixed:


#!/bin/sh
PIDS=`cat /tmp/ices.pid`
ARTIST=`sed -n -e '7p' /tmp/ices.cue.$PIDS`
TITLE=`sed -n -e '8p' /tmp/ices.cue.$PIDS`
echo Now playing: $ARTIST - $TITLE > /path/to/file

thanks for your help :)

hotleadpdx
01-19-2003, 02:14 PM
Good to hear you have it solved. Another way to log the output of the script is to create a logging shell script to use as a 'wrapper' for the executable script. This would allow it to be more flexible (for instance, you could capture and append the date and time of the last run to the log to maintain a chronological sequence of logs).

Just an idea.