User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » Shell Scripts and Crontab Page [1]  
darkone
(\/) (;,,,;) (\/)
11609 Posts
user info
edit post

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, 2007

ym=$(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 it
if [ -d /home/disk/kosh3/trmmorbits/version6/$ym ]
then
echo "directory exists"
else
mkdir /home/disk/kosh3/trmmorbits/version6/$ym
fi

cd /home/disk/kosh3/trmmorbits/version6/$ym #change local directory so ftp commands put the files in the correct place

ftp -p -n -i disc2.nascom.nasa.gov <<END_SCRIPT
user anonymous anonymous@anonymous.com
binary
cd /data/s4pa/TRMM_L1/TRMM_1B11/$yr/$jd
mget *.HDF
cd /data/s4pa/TRMM_L2/TRMM_2A12/$yr/$jd
mget *.Z
cd /data/s4pa/TRMM_L2/TRMM_2A23/$yr/$jd
mget *.Z
cd /data/s4pa/TRMM_L2/TRMM_2A25/$yr/$jd
mget *.Z
bye

END_SCRIPT

ftp -p -n -i disc3.nascom.nasa.gov <<END_SCRIPT
user anonymous anonymous@anonymous.com
binary
cd /data/s4pa/TRMM_L1/TRMM_1C21/$yr/$jd
mget *.Z
bye

END_SCRIPT

gzip *.HDF

gunzip 1C21*.Z
gzip *.HDF

gunzip 2A12*.Z
gzip *.HDF

gunzip 2A23*.Z
gzip *.HDF

gunzip 2A25*.Z
gzip *.HDF

3/5/2007 4:21:32 PM

Bakunin
Suspended
8558 Posts
user info
edit post

Gee, I wonder if the log file's contents, or lack thereof, might be a relevant detail.

3/5/2007 5:26:24 PM

darkone
(\/) (;,,,;) (\/)
11609 Posts
user info
edit post

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

Bakunin
Suspended
8558 Posts
user info
edit post

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

split
All American
834 Posts
user info
edit post

my first guess would be a PATH issue

instead 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

darkone
(\/) (;,,,;) (\/)
11609 Posts
user info
edit post

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

split
All American
834 Posts
user info
edit post

setenv and .cshrc aren't for the bash shell (which your script is running)
after your comments, just add a PATH line

PATH=/bin:/usr/bin:/usr/local/bin:/opt/local/bin:/whatever/bin

3/5/2007 11:07:15 PM

scud
All American
10804 Posts
user info
edit post

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

A Tanzarian
drip drip boom
10994 Posts
user info
edit post

Quote :
"Where/how are you making the crontab entry?"

3/6/2007 7:46:41 AM

State409c
Suspended
19558 Posts
user info
edit post

Quote :
"I guarantee you it's a uid issue What uid/gid is crond running as?"


This was my hunch, too. I was just lazy last night and didn't feel like posting it.

3/6/2007 8:15:06 AM

darkone
(\/) (;,,,;) (\/)
11609 Posts
user info
edit post

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

 Message Boards » Tech Talk » Shell Scripts and Crontab Page [1]  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.38 - our disclaimer.