1845560 Members
2662 Online
110245 Solutions
New Discussion

Re: crontab run error.

 
stelecom
Occasional Advisor

crontab run error.

Dear All,

I am set my cronjob to run a script, this script will generate a report file. If I run it by command line, it run ok, but I setup it to run by Cronjob. I generate a file with size =0. Please help me.

Many thanks,
NQV
9 REPLIES 9
RAC_1
Honored Contributor

Re: crontab run error.

One thing that everyone must understand before putting scripts into crontab, is that cron enviroment is very minimal. All the variables, paths, required resouces should be defined in the script itself.

Check what ever variables you use are defined in script itself. Also use absolute paths for calling commands, storing files etc.
There is no substitute to HARDWORK
Arunvijai_4
Honored Contributor

Re: crontab run error.

Check /var/adm/cron/log for more details..

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
stelecom
Occasional Advisor

Re: crontab run error.

I check log file, but it do not show anything. I don't thinks it relate with Env variables.

Regards,
Vu
stelecom
Occasional Advisor

Re: crontab run error.

This is content of my log file:

> CMD: /usr/bin/ksh /tuxedo/cron/sers_rpt.sh
> tuxedo 23437 c Fri Oct 28 11:54:00 TST 2005

NQV
Rory R Hammond
Trusted Contributor

Re: crontab run error.

RAC is correct.

If your job runs from the command line
do
env > file

evaulate the file, Edit your cron script. add and set the variable in your script. If you get all the variable set everything should run.

Rory
There are a 100 ways to do things and 97 of them are right
Victor Fridyev
Honored Contributor

Re: crontab run error.

I agree with RAC, the problem seems to be in a difference between environment. Put the follwing:
. ~/.profile
In the beginning of the script. This should resolve the problem.
Usually it's enough to restore only full PATH variable
Good Luck
Entities are not to be multiplied beyond necessity - RTFM
stelecom
Occasional Advisor

Re: crontab run error.

Please tell me more detail

this is content of crontab

49 15 * * * /tuxedo/cron/sers_rpt.sh

Thanks.
NQV
Steven E. Protter
Exalted Contributor

Re: crontab run error.

Trying again:

cron jobs have no environment.

Commonly the script works fine from the command line and fails in cron because the PATH variable is not set.

There are lots of ways to fix it.

You can manually set PATH in the script. You can run the root profile as Victor suggested.

Add this to the job.

set -x

Right after the shell statement at the top.

This should provide you provide you a lot of detail that should lead you to this conclusion: Read the prior suggestions carefully, try one and see that it resolves the problem.

Also for cron to run properly there must be some space in the var filesystem:

bdf /var

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Rory R Hammond
Trusted Contributor

Re: crontab run error.



I disagree with the analysis that it is just a PATH problem. (It could be) I also disagree with sourcing the .profile in cron scripts.


PATH can be just one of the Problems. Sourcing .profiles sometimes cause problems like "not a tty device". The issue is you need to set the all the environmental variables that your shell script requires. Before you execute the work portion of your script.

For example: Service ID's like ORACLE commonly has environmental variables set like ORAHOME and SID. These are usually set in your .profile. On CRON jobs you need to set all your variables in your shell script.

The .profile commonly sets TERM= by running some sort of tset command. You would not want to run tset via cron because you would receive tty errors.

To fix your problem EVAULATE all of your environment variables and set them in you cron script.

Good Luck
There are a 100 ways to do things and 97 of them are right