Operating System - HP-UX
1834798 Members
2893 Online
110070 Solutions
New Discussion

job run in cron produces no output

 
SOLVED
Go to solution
Dave Chamberlin
Trusted Contributor

job run in cron produces no output

I have a status script (ksh) that redirects its output to a log file. The script works fine, except when run as a cron job. In that case the log file is created but is empty. Any ideas? Thanks
6 REPLIES 6
Navin Bhat_2
Trusted Contributor

Re: job run in cron produces no output

did the write permission on the file change? Maybe a umask issue for that user who creates the file.
Mel Burslan
Honored Contributor

Re: job run in cron produces no output

are you getting this result in the root's mail for some reason ? (assuming it is in the root's crontab)
if so, you may have a problem with the redirection.
You may try posting the scripts or at least the related parts of it, if it is too long.
________________________________
UNIX because I majored in cryptology...
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: job run in cron produces no output

In almost all cases, failure of cron'ed script that otherwise run fine stem from two causes: 1) The need to set and export environment variables including PATH that are not set by cron's intentionally sparse environemnt. 2) The failure of a command that expects stdin to be an interactive device (e.g a terminal).

2) can be addressed by the test
if [ -t 0 ]
then
echo "Interactive"
else
echo "Batch"
fi

A typical error occurs with a cron'ed su - user command. The - sources user's .profile and it almost always have commands like tset and stty that expect a terminal.
If it ain't broke, I can fix that.
Tom Ward_1
Honored Contributor

Re: job run in cron produces no output

Be sure you have standard out and standard error going to your log file. That way error will give you a clue as to what is wrong.

Do you have a path statement in the script or call commands with full pathing? The environment for minimal and will not have the same values as your shell session.

HTH,
Tom
Victor Fridyev
Honored Contributor

Re: job run in cron produces no output

Hi,
Could you please check a mail for the user which run this cron job. Additionally please check whether somewhere in the script or crontab you use indefined environment variable. Take into account that scripts which run under crontab don't obtain full user's environment. You can see defined variables if run command env in a cron job.

HTH.
Entities are not to be multiplied beyond necessity - RTFM
Dave Chamberlin
Trusted Contributor

Re: job run in cron produces no output

Thanks all for the super fast responses!!
Clay was closest to the problem - PATH being the issue. Root had the command is its PATH, but cron wouldn't pick that up - so the script was running but not one of the commands inside it. I put the full path in the script a viola...sheepish look here...

Thanks again