1827066 Members
4161 Online
109713 Solutions
New Discussion

Script Retunns "rc=1"

 
SOLVED
Go to solution
Leon Collins
New Member

Script Retunns "rc=1"

I'm not very proficient at scripting. Still working on getting the hang of it. I'm sitting in for the person who wrote the attached, and I'm trying to figure out why this job, when cron runs it, comes back in the log file with:
> larry 1355 c Mon Jan 23 22:00:00 PST 2006
< larry 1355 c Mon Jan 23 22:00:15 PST 2006 rc=1.

I'm on an n4000-55 running 11.11.

Any help would be greatly appreciated.
5 REPLIES 5
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Script Retunns "rc=1"

This is pretty much the classic mistake made under cron. Cron has an intentionally very sparse environment so that little thinhs like PATH and HOME either are greatly abbreviated or not set at all.

This is the first offending line that I saw (but there may be many others):
Script_Dir=${HOME}/SQL

${HOME} is not yet set.

The solution when running under cron is to set and export these values very early in the script OR create a wrapper script that is called directly by cron; it's job is to set and export any needed variables and then call your "real" script.

you might do something like this in the wrapper script:

#!/usr/bin/sh

PATH=${PATH}:/usr/lbin:/usr/local/bin
HOME=/home/thisuser

typeset -i STAT=0
export PATH HOME

/xxx/yyy/realscript.sh
STAT=${?}
exit ${STAT}

If it ain't broke, I can fix that.
Sandman!
Honored Contributor

Re: Script Retunns "rc=1"

Run the script in debug mode replacing its first line i.e.

#!/usr/bin/ksh
with the one below...
#!/usr/bin/ksh -x

cheers!
Bill Hassell
Honored Contributor

Re: Script Retunns "rc=1"

rc=1 means that the return code from the script was 1. Normally, a script that finishes normally will exit with a return code = 0, so something inside the script has failed. I am assuming that your script runs fine when you try it manually, then the most likely problem is with the environment as Clay mentions. By running your script with -x, either using the #! line as sandman points out (you are using #! as line 1, right?) or insert the line:

set -x

as the first line after #!. Now any error messages from your cron job will be emailed to the owner of the cron job. If mail is not setup or not convenient, just add the redirect codes to the cron job as in:

1 2 3 * * /home/user_name/myscript > /var/tmp/myscript.log 2>&1

Now, anything shown by your script will be redirected into the log file: /var/tmp/myscript.log


Bill Hassell, sysadmin
Leon Collins
New Member

Re: Script Retunns "rc=1"

Thanks all. I will definitely try your suggestions and let you know how it worked. I appreciate the time you took. I will assign points as soon as I get the hang.
Leon Collins
New Member

Re: Script Retunns "rc=1"

Sorry about taking so long to get back. The solutions you all provided helped me get it straigt. I'm still having a little problem, but believe I'll solve it when given time. Thanks so much.