I have the following shell script set to run every morning before I come into work. It grabs a bunch of remote data and archives it on one of our big storage servers. The script works when I run it though the command line. I set it up to run under crontab Friday. It was supposed to run over the weekend, but it didn't. Can anyone here see a reason why it wouldn't work when run by cron?30 6 * * * file/path/scriptname >> file/path/scriptlog.log
#!/bin/bash# TRMM archive FTP script# This script is intended to be run everyday either manually or by cronjob.# This script will download all the previous day's TRMM files and archive then# in the proper place.# Written By: Matthew Miller, NCSU, 2007ym=$(date -u -d yesterday +%Y%m) #get yesterday's year and month (YYYYMM)yr=$(date -u -d yesterday +%Y) #get yesterday's year (YYYY)jd=$(date -u -d yesterday +%j) # get yesterday's Julian day (DDD)#make sure directory exists, else create itif [ -d /home/disk/kosh3/trmmorbits/version6/$ym ]then echo "directory exists"else mkdir /home/disk/kosh3/trmmorbits/version6/$ymficd /home/disk/kosh3/trmmorbits/version6/$ym #change local directory so ftp commands put the files in the correct placeftp -p -n -i disc2.nascom.nasa.gov <<END_SCRIPTuser anonymous anonymous@anonymous.combinarycd /data/s4pa/TRMM_L1/TRMM_1B11/$yr/$jdmget *.HDFcd /data/s4pa/TRMM_L2/TRMM_2A12/$yr/$jdmget *.Zcd /data/s4pa/TRMM_L2/TRMM_2A23/$yr/$jdmget *.Zcd /data/s4pa/TRMM_L2/TRMM_2A25/$yr/$jdmget *.ZbyeEND_SCRIPTftp -p -n -i disc3.nascom.nasa.gov <<END_SCRIPTuser anonymous anonymous@anonymous.combinarycd /data/s4pa/TRMM_L1/TRMM_1C21/$yr/$jdmget *.ZbyeEND_SCRIPTgzip *.HDFgunzip 1C21*.Zgzip *.HDFgunzip 2A12*.Zgzip *.HDFgunzip 2A23*.Zgzip *.HDFgunzip 2A25*.Zgzip *.HDF
3/5/2007 4:21:32 PM
Gee, I wonder if the log file's contents, or lack thereof, might be a relevant detail.
3/5/2007 5:26:24 PM
Writing the output to the log file was a new thing I did to aid my troubleshooting. I did that this morning, but I won't get any new output until the script runs again. I know I could force the script to run, but I wanted to make sure there wasn't anything in the code that I was missing. I felt I needed a fresh set of eyes.If I don't get any feedback from TWW or helpful information from the output log, I'm going to place echo commands before and after every command to try and find out where things screw up or to see that it actually runs. I'll also get it to echo all the variable and environment information. This has just been a " back burner" task for me, but it's becoming annoying. All I wanted to do was to save myself a little time durning my day.
3/5/2007 5:36:05 PM
So do you know if it's your crontab entry or your script? Where/how are you making the crontab entry? Assuming the script works, the crontab entry looks right, it seems like the cron daemon isn't being made aware of your request.
3/5/2007 5:50:09 PM
my first guess would be a PATH issueinstead of waiting until 6:30 tomorrow, just change it to run now to figure out what is happening. once it works, then change it back to run daily
3/5/2007 6:05:44 PM
How do I tell it just to load my .cshrc file so all my paths will be set?Or would it be better to do something like:
setenv PATH /whatever/the:/fuck/the/path:/needs/to/be
3/5/2007 8:23:17 PM
setenv and .cshrc aren't for the bash shell (which your script is running)after your comments, just add a PATH linePATH=/bin:/usr/bin:/usr/local/bin:/opt/local/bin:/whatever/bin
3/5/2007 11:07:15 PM
I guarantee you it's a uid issue What uid/gid is crond running as?Does it have rwx on the script?Can it write to that directory?
3/6/2007 12:12:13 AM
3/6/2007 7:46:41 AM
3/6/2007 8:15:06 AM
I just figured out what was wrong. It was a problem on NASA's end. The script is supposed to grab the satellite data from the previous day. Well, it looks like NASA missed a few days or something over the weekend. The data is normally up a few hours after it's collected, but NASA is currently 4 days behind. The script was failing because it was trying to get FTP data that wasn't there. It's annoying, but it's nice that it wasn't something I overlooked. I think I'm going to rewrite the script to gab week old data instead of day old data. That way it will give me more of a cushion if NASA gets behind on their data processing.As for uid/gid issues, the cron runs under the same uid/gid that I do. Thus, if I can do it so can cron.
3/6/2007 11:23:31 AM