Cron - Not working properly

Hi,
I do have three scripts. Whcih inserts records into a table using sqlldr, creating some reprot files etc. The first script will call the second and then the second will call the third. When I run my first script from the shell prompt, all my operation are completed successfully. If I do the same using a cron , then its working partially. Not able to insert records, log files not generating etc.. Is there any seeting to be made in cron or how can this be solve ?? Help me out ... I am using HP-Unix

Do a search on this site. 99% of cron problems are due to people making wrong assumptions about the environment.

cron gives you a minimal environment, it does not run your .login, .profile or whatever.

I am using unzip in my second script. But that command is returning 127. As i said earlier if I run my first script from the prompt, then it call the second script, it does the unzip operation succesfullly and the process goes on. Only when the first script is scheduled in a cron, the unzip fails and after that nothing is working. Wat can be done for this ??

What can be done first is to start here with the FAQs

Unzip returns 127 = ???
And show us your script perhaps.

unzip myfile.zip > /dev/null
echo $?

If i store the above lines in a script and run that manually then its working fine. If i schedule the script using cron , htne its returning 127. What could be cause ??

try giving the absolute path of unzip

should be in /usr/bin/unzip

and wrap the commands in a script and redirect the script output to a log file to see what error is actually displayed.

Erm, when you run 'unzip myfile.zip', are you running the command from the directory where myfile.zip is present? What I mean is, does your cron script actually do a 'cd' to the directory where the myfile.zip file is present?

When you run the script you might be running it from the directory where the file is already present. However, when a script runs through cron, the working directory is usually the home directory of the user whose cron is running the script.

Hi,
The locations are given correctly. Even I tried running my script from the home directory, by giving the whole path. Its executing perfect. the only probelm is when i schedule my script in cron, its throwing the error. I do have many operaiton in my script. Like unzip, I use sql loader , sql plus commands too. All are giving error when scheduled in cron. So what else can be done ???

I tried /usr/bin/unizip .. Its telling
ksh : /usr/bin/unizip : not found

Make sure your paths are correct. I see you've got "/usr/bin/unizip" instead of "/usr/bin/unzip". Check for where your commands are using "whereis cmd_name", e.g. %whereis unzip.

Hi,
I gave whereis unzip. Its showing :

unzip:

So i too doubt the location about that command. But still , its working when i run the script manually, instead of using the CRON. As shown above for unzip, the same is coming for sqlldr and sqlplus. So how can i use them with cron ??

I am really confused about this situation..

Is there any chance you can show us your entire script ??

It might be something else that you have in it that's causing it to run standalone and not via cron.

I think posting your script might help.Just out of curiosity: Make sure you have $ sign in front of your commands in your script, e.g. $unzip file_name ,etc.

why is that?

Why to put $ ???
More over hope u remember the point "script works fine when executed manually" ....

My script is just as follows:

#!/usr/bin/sh

ZIPFILE_PATH=/...
MYLOCATION=/...

cd MYLOCATION

unzip $ZIPFILE

FILECOUNT=`ls -l | wc -l`

if [ $FILECOUNT -eq 7 ]
then
do some process
else
send an error mail

So for me, when i schedule the above script in CROn, always i do get the error mail. If i run it manually then "do some process" is happening.

what can be done ???

Shouldn't the unzip command read:

unzip $ZIPFILE_PATH # here I am assuming that the ZIPFILE_PATH holds the entire path, including the filename.

I don't see you setting $ZIPFILE anywhere in the script.

As previously said , you just need to load your login profile (.profile, .login or whatever it is) for the cron to mimic the environment you are in when you're on the shell, try that and everything should be ok.

hi blowtorch,

its was a samll mistake while typing here...

its not $ZIPFILE ..
it should be

unzip $ZIPFILE_PATH

hi andryk,
loading my .profile means ... i dont get you .. just executing that file or not clear .. but one thing . simple jobs scheduled in cron is working fine ..

I want to add one more point here ..

when i gave :
$whereis unzip , its showing

unzip :

So i think its not able to find the location of the unzip command.. Could this be the reason why cron is not able to execute the unzip command ??

Yes, the way of loading your profile in your batch is '. $HOME/.profile', there's a space between the dot and the $ (without the quote of course :))

Maybe, you may want to search for it: find /usr -name unzip -print or even from the root.

Good luck.