Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problems running script via cron 2

Status
Not open for further replies.

iguanasleep

Programmer
Feb 27, 2003
11
0
0
US
I did search thru all other cron prob postings here and tons elsewhere, sifted repeatedly thru the crontab and cron man pages, tried anything that seemed remotely applicable but still no luck. let's see if any of you can puzzle this one out - i'm stumped :).

I have a script that I have set to run as a cron job. running the script stand-alone from the command line works beautifully (creates some output file), but running it via cron - doesn't complete.

say the script running via cron looks like this (tho for testing purposes I've been having it run at many different times during the day):
0 4 * * M-F /RelMan/rates/myscript

the script itself contains 2 lines:
#!/bin/ksh
/RelMan/rates/action alpha

where 'action' is a script file that contains a line of java and some path variables for completing the java execution, and alpha is just a variable that gets passed into 'action' that the contents of 'action' depend on.

I checked the cron log as well and there is no return code given after the lines where it logs execution of the job (which I assume means rc=0 which = successful). Earlier in my attempts it listed an rc=1, meaning the job itself didn't complete, which I fixed (I think it was a permissions thing). So now it looks as tho cron sees that it completed, but the actual script itself (i.e. subsequent generation of the file via the java execution) is failing to complete.

I've tried sticking in echos as "breakpoints" of sorts, but haven't gotten anything useful spit back at me.

Anyone have any thoughts as to any obvious trip-ups when executing code/scripts via a cron job, or even just better ways of breakpointing to figure out what's not happening and where it's not happening at?

incidentally - this is running under a user's cron job, but I've even tried running it as a cron job under root as same thing.

thnx!!
 
Have you set the PATH variable in the script that the cron job is running so that it contains all of the directories that are in your path when you run it from the command line?
 
Put the following at the start of the script.

#!/bin/ksh

set -x

exec 1> mylog 2>&1 #make sure you have write priv to mylog


mylog will have the trace of all lines executet

HTH
 
it was pmurray99's that ended up being the clincher for me figuring out the problem, which itself was tied to what bi suggested.

i added the lines as you suggested to create a log file which was exactly what I was seeking to be able to troubleshoot where the script(s) were blowing up. and that allowed me to see exactly what I needed. the problems themselves were so painfully obvious and simple - a file being referenced by a cat & grep call, and then another script called - neither of which were explicitly pathed, just named by file as tho being executed from with in that dir. that worked fine of course in flat execution, but not via a cron shell where i wasn't in that dir. :)

yeesh - i knew it was something so simple, but due there being a succession of scripts getting called and me sifting thru all of them over and over, i missed what was right in front of my face.

anyway - thnx hugely to you both, and pmurray99 - thnx for giving me a good excuse to learn more about what exec does, as I wasn't very familiar with it.

you both rock, thnx for taking the time to respond!
tara
 
Thanks for the star! It's usually the most obvious things that get overlooked!

I've saved pmurray's suggestion -- it looks like one of those things that will come in very handy one day.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top