Operating System - HP-UX
1833930 Members
2558 Online
110063 Solutions
New Discussion

Re: crontab erroring out with rc=1

 
siddharthC
Occasional Advisor

crontab erroring out with rc=1

Hi,

I am trying to run script through crontab but it is throwing following error.

CMD: . /data/vision/scripts/test.sh>>/data/vision/scripts/test.log
vision 13619 c Thu Aug 10 18:10:00 IST 2006
vision 13619 c Thu Aug 10 18:10:00 IST 2006 rc=1
------------
extract from cron.allow file
root
adm
uucp
applcrp1
vision
-------------
there is no cron.deny file

I am able to run the script from the command prompt.

Enclosed is the script.

Thanks in advance.

Siddharth



14 REPLIES 14
Pupil_1
Trusted Contributor

Re: crontab erroring out with rc=1

what's the syntax in the crontab? Hope U've given the absolute path of the script in crontab !
There is always something new to learn everyday !!
Jeff Schussele
Honored Contributor

Re: crontab erroring out with rc=1

Hi Siddharth,

Remember that a cron job has a very sparse environment. You should source the env vars you need for this script to run. And don't just run the .profile for that user unless you're sure that there are no routines that need a tty to execute.

HTH,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
A. Clay Stephenson
Acclaimed Contributor

Re: crontab erroring out with rc=1

You have made the classic error for any cron'ed job and that is to assume that when you run a command under cron as a certain user (e.g. oracle) that you also inherit that user's normal environment. The environment under cron is intentionally very sparse. You must explicitly set and export PATH and any other needed environemt variables such as ORACLE_HOME and ORACLE_SID. Normally these assignments and exports are done very early in your cron'ed script.
If it ain't broke, I can fix that.
Pete Randall
Outstanding Contributor

Re: crontab erroring out with rc=1

I suspect that it is not a problem with cron but rather a problem with the script. I was unable to open your attachment, but the usual problems with cron executed scripts are with the environment. The cron environment is intentionally sparse (see man crontab), so you need to make sure to use all full path names and not assume that any environment variables are set. One way to do this is to source an environment script at the beginning of your script.


Pete

Pete
Victor Fridyev
Honored Contributor

Re: crontab erroring out with rc=1

Hi,

Please take into account that crontab does not give to running scripts full environment, including PATH.
You have either in beginning of the script to execiute:
. ~/.profile , which is preferable
or to use full paths in each command.

Usually all cron scripts problems are connected to lack of environment.

HTH
Entities are not to be multiplied beyond necessity - RTFM
Jonathan Fife
Honored Contributor

Re: crontab erroring out with rc=1

Is anything added to test.log?

Are you setting your ORACLE_SID in some wrapper script or within the cron line?
Decay is inherent in all compounded things. Strive on with diligence
siddharthC
Occasional Advisor

Re: crontab erroring out with rc=1

I have given the following syntax for scheduling the job


30 * * * * . /data/vision/scripts/cp_arc_remote_loc_ver04.sh>>archive.log
Pupil_1
Trusted Contributor

Re: crontab erroring out with rc=1

Try changing the crontab entry as follows.

30 * * * * /data/vision/scripts/cp_arc_remote_loc_ver04.sh>>/tmp/archive.log

Assuming that the absolute path of the cp_arc_remote_loc_ver04.sh script is /data/vision/scripts/ !!
There is always something new to learn everyday !!
Pupil_1
Trusted Contributor

Re: crontab erroring out with rc=1

Might be worth replacing the '30' with a smaller value to check it sooner than the 30 mins !!
There is always something new to learn everyday !!
siddharthC
Occasional Advisor

Re: crontab erroring out with rc=1

I have sourced the required environment but still getting the same error.
OldSchool
Honored Contributor

Re: crontab erroring out with rc=1

Don't recall the "bash" syntax, but there should be something along the lines of "set -x" that will cause each command to echo prior to execution.

Try that and see if it will tell you which command is failing.

Its almost got to be either a path issue, or possibly something from the .bashrc file that needs to be set up in the script for it to run
Jonathan Fife
Honored Contributor

Re: crontab erroring out with rc=1

Let's add some additional debugging. Add a -x in the shell invocation line:

#!/bin/bash -x

And redirect all output to a separate log file. e.g.:

30 * * * * . /data/vision/scripts/test.sh > /tmp/test.log 2>&1

What is in /tmp/test.log after that runs?
Decay is inherent in all compounded things. Strive on with diligence
A. Clay Stephenson
Acclaimed Contributor

Re: crontab erroring out with rc=1

Sourcing .profile may not work because almost certainly the .profile has commands like tput, tset, tabs, ... which expect stdin to a tty device so you would have to
surround those commands with something like
if [ -t 0 ]
then
tput
...
fi

or better still have your cron'ed script and .profile source a file which sets and exports the needed environment variables.
If it ain't broke, I can fix that.
siddharthC
Occasional Advisor

Re: crontab erroring out with rc=1

Hi ,

I have tried including the .profile and environment. Still no sucess. Enclosed is the debug file.