1834623 Members
2731 Online
110069 Solutions
New Discussion

Re: Cronjob

 
Scott D. Allen
Regular Advisor

Cronjob

I've got a cronjob that runs fine from the command line as root, but doesn't run in the cron. Actually, it runs, but it dumps out before executing correctly and doesn't produce any errors.

30 * * * * /opt/scripts/script > /var/tmp/script.log 2>&1

It produces a log file inside the script, which gets created every half hour, but it's empty and so is the log file.

--Scott
"Sometimes the devil you know is better than the devil you don't know."
4 REPLIES 4
Andreas Voss
Honored Contributor

Re: Cronjob

Hi,

don't know what script you have.
If it's a bourne/korn (sh/ksh) script
insert at the top a line like:
set -x
this generates a trace to stdout.
Perhaps you can look in the mail for these
messages.

Regards

Andrew
Brian M. Fisher
Honored Contributor

Re: Cronjob

My guess is there are environmental variables that are not getting set when the job is run via cron. Make sure to set all required variables within the script.

If you do not want a new log file created at each execution use >> instead of >.

Brian
<*(((>< er
Perception IS Reality
Scott D. Allen
Regular Advisor

Re: Cronjob

Thanks guys. I was using the wrong syntax in one of my commands and it was doing an exit 0.

--Scott
"Sometimes the devil you know is better than the devil you don't know."
Chris Ermlich
New Member

Re: Cronjob

Scott,

Not knowing what your script does, you might want to check if any directories or commands are being used in the script that have to have 'root' access (since it's running fine from the command line when executed as 'root'). Is the cron job running as 'root' or as user 'xyz'?

Chris :-)
"Everyone has a photographic memory. Some don't have film."