System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

Cron log showing error as rc=1

 
SOLVED
Go to solution
Venkatesan_5
Frequent Advisor

Cron log showing error as rc=1

I have a cron user abcd and the script file is /home/abcd/script/auto_run_db_extract.ksh

the user abcd has a cron file under /var/spool/cron/crontabs/abcd

The crontab entry in abcd is

01 19 * * * /home/abcd/script/auto_run_db_extract.ksh

Till Dec 12th the script was executing fine, but since Dec 13th the script is not working.

No changes made to crontab file or to the script.

Since Dec 13th the cronlog entry shows

> abcd 9475 c Thu Dec 11 19:01:00 CST 2008
< abcd 9475 c Thu Dec 11 19:02:52 CST 2008
> CMD: /home/abcd/script/auto_run_db_extract.ksh
> abcd 14909 c Fri Dec 12 19:01:00 CST 2008
< abcd 14909 c Fri Dec 12 19:02:08 CST 2008
> CMD: /home/abcd/script/auto_run_db_extract.ksh
> abcd 17734 c Sat Dec 13 19:01:00 CST 2008
< abcd 17734 c Sat Dec 13 19:01:00 CST 2008 rc=1
> CMD: /home/abcd/script/auto_run_db_extract.ksh
> abcd 17787 c Sun Dec 14 19:01:00 CST 2008
< abcd 17787 c Sun Dec 14 19:01:01 CST 2008 rc=1
> CMD: /home/abcd/script/auto_run_db_extract.ksh
> abcd 29078 c Mon Dec 15 19:01:00 CST 2008
< abcd 29078 c Mon Dec 15 19:01:00 CST 2008 rc=1
> CMD: /home/abcd/script/auto_run_db_extract.ksh
> abcd 17490 c Tue Dec 16 19:01:00 CST 2008
< abcd 17490 c Tue Dec 16 19:01:01 CST 2008 rc=1
> CMD: /home/abcd/script/auto_run_db_extract.ksh
> abcd 23858 c Wed Dec 17 19:01:00 CST 2008
< abcd 23858 c Wed Dec 17 19:01:00 CST 2008 rc=1

The script file contents is

______________________________________
if [[ -d /oracle/abcadmin/lost+found ]]
then
export ORACLE_BASE=/oracle/app
export ORACLE_HOME=/oracle/app/product/9.2.0
export ORACLE_SID=ICIPRDB
export SHLIB_PATH=$ORACLE_HOME/lib32:$ORACLE_HOME/rdbms/lib32
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib:$ORACLE_HOME/rdbms/lib
export TWO_TASK=
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
export PATH=$PATH:/usr/local/bin:$ORACLE_HOME:$ORACLE_HOME/bin:$ORACLE_HOME/lib:/usr/sbin:/etc:.:$ORACLE_HOME/OPatch
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib:$ORACLE_HOME/network/jlib; export CLASSPATH
umask 022
`uname -n`'[${ORACLE_SID}]: $PWD> '; export PS1
NLS_DATE_FORMAT='Mon DD YYYY HH24:MI:SS'; export NLS_DATE_FORMAT
export NLS_LANG=american_america.AL32UTF8
sqlplus -S "reporting_user/fnsw@ABCPRDB" @/home/abcd/script/reporting_db_extract.sql

cp /home/abcd/data/receive/* /home/abcd/data/old_data
scp -rp /home/abcd/data/receive/* abcd@x.x.x.x:/home/abcd/data/receive
scp -rp /home/abcd/data/receive/* abcd@x.x.x.x:/home/abcd/data/old_data
rm -f /home/abcd/data/receive/*
else
exit
fi
_________________________________________

May I know why the script failed and what is the meaning of rc=1 in cron log file.
13 REPLIES
Grayh
Trusted Contributor

Re: Cron log showing error as rc=1

looks like there are syntax errors in the script... The script should always start with #!/usr/bin/sh

You can also try:-
# /sbin/init.d/cron stop
# /sbin/init.d/cron start

try PATH=${PATH}:${ORACLE_HOME}/bin
${PATH} is another way of writing $PATH.
James R. Ferguson
Acclaimed Contributor

Re: Cron log showing error as rc=1

Hi:

Cron is telling you the return code (rc) of the last command. In your case the last command returned a value of one (1).

Regards!

...JRF...
Venkatesan_5
Frequent Advisor

Re: Cron log showing error as rc=1

Thanks Grayh,

The script file has not been modified till Dec13 and it has been working till then.

Also the cron is executing this file using /usr/bin/sh only.

With regard to path also the script is not modified. I dont know what happened all of a sudden.

Let me restart my cron and will let you know.

Thanks for your reply.
Grayh
Trusted Contributor

Re: Cron log showing error as rc=1

If rebooting the cron works... it should be fine..

>No changes made to crontab file or to the script.

So you may try to run the script independent of cron.

Also check the permissions for file if they might have changed, and your scripts might be failing.

And check if the directory for cron.allow and at.allow is "/usr/lib/cron"

Bill Hassell
Honored Contributor
Solution

Re: Cron log showing error as rc=1

> The script file has not been modified till Dec13 and it has been working till then.

Nothing has changed on your computer? A full filesystem (ie, /home), you have exceeded filesystem quotas, a change in the database logins, scp is failing due to a public key problem, etc... For most commands, the return code is the error number, also known as errno, and errno=1 means:

from /usr/include/sys/errno.h:
errno 1 = EPERM /* Not super-user */

[EPERM] Not owner. Typically, this error indicates an attempt
to modify a file in some way forbidden except to its
owner or the superuser, such as to change its mode. It
is also returned for attempts by ordinary users to do
things for which they need, but lack, a special
privilege.

Even though this is being run as root, your script depends on other subsystems such as sql and another computer. Don't run it in cron until you run it from a root login shell. And run it this way:

sh -x /home/abcd/script auto_run_db_extract.ksh

The -x will trace each step. If that works OK, put the line:

set -x

at the top of your script and let cron run it. You'll get an email with the trace and be able to see which line is failing.

> Also the cron is executing this file using /usr/bin/sh only.

It is a bad idea to allow any scripts without the #!/usr/bin... header line. Without this line, someday a script will be run from a non-standard shell and cause problems. Always include #!/usr/bin/sh for your POSIX shell scripts.


Bill Hassell, sysadmin
Venkatesan_5
Frequent Advisor

Re: Cron log showing error as rc=1

Thanks Grayh,

I have rebooted cron. I need to wait till the server time tickles 19:01.

With regard to running the script manually,
the user is saying that the @ symbol in the following line is giving some error.

sqlplus -S "reporting_user/fnsw@ABCPRDB" @/home/abcd/script/reporting_db_extract.sql

I dont have the exact error message now. So what the user is doing is he logs on to sqlplus and does his tasks which goes smoothly.

I will let you know after 19:01 hrs CST.

Thanks
Grayh
Trusted Contributor

Re: Cron log showing error as rc=1

My users also had the @ issue many a times... Just that their .profile needs a bit of modification...

'stty -a' should show as:

kill = ^U -------->which is the default terminal setting.

& stty kill ^U
Patrick Wallek
Honored Contributor

Re: Cron log showing error as rc=1

I seriously doubt that stopping / starting cron will help here.

The user that is running this job needs to check their mail on the HP-UX system. Cron will send an e-mail to the user account that runs the job EVERY TIME it runs.

From this e-mail you should be able to see how / where it is failing.

I would modify the line in cron so that I get an e-mail after the script runs. Do something like:

01 19 * * * /home/abcd/script/auto_run_db_extract.ksh 2>&1 | mailx -s "Output from auto_run_db_extract.ksh cron job" user@domain.com

OldSchool
Honored Contributor

Re: Cron log showing error as rc=1

Bill note "Even though this is being run as root, your script depends on other subsystems such as sql and another computer."

Actually, he said user "abcd" ran the job out of cron, so it gets id / permissions, correct?

I'd suspect a (possibly inadvertant) change in one of the directories noted for the "scp" or the "rm"....possibly others depending upon what's in "reporting_db_extract.sql"

also of note is the fact that the orignal script (or at least the portion posted) will *NOT* run if it can't find "lost+found", which makes absolutely no sense at all, as it doesn't use anything located there.

interesting that the original script is .ksh, but doesn't have the #! line...
Dennis Handly
Acclaimed Contributor

Re: Cron log showing error as rc=1

>May I know why the script failed and what is the meaning of rc=1 in cron log file.

You'll need to debug your script to find which command is returning a bad exit status.

From your script fragment:
if [[ -d /oracle/abcadmin/lost+found ]]; then
...
rm -f /home/abcd/data/receive/*
else
exit
fi

You may want to reverse the logic so you don't have too much indentation:
if [[ ! -d /oracle/abcadmin/lost+found ]]; then
exit
fi
...
rm -f /home/abcd/data/receive/*

Typically that "rm -f" shouldn't return an error unless there is a permission issue.

If it fails somewhere above, you would have to use Bill's "set -x" to track it.

>Bill: For most commands, the return code is the error number, also known as errno, and errno=1 means:

Not always. 1 is the standard bad exit status value: EXIT_FAILURE
Venkatesan_5
Frequent Advisor

Re: Cron log showing error as rc=1

Hi All,

Thanks for your valuable reply.

The issue is resolved now.

The culprit is the first line in the script
if [[ -d /oracle/abcadmin/lost+found ]]

the file /oracle/abcadmin/lost+found was not found due to which the script failed.

We changed the script and now its working.

Regards,

Venkatesan.
OldSchool
Honored Contributor

Re: Cron log showing error as rc=1

gee...thanks....i told you exactly where to look, and it wasn't all that helpful??????
Dennis Handly
Acclaimed Contributor

Re: Cron log showing error as rc=1

>The culprit is the first line in the script
if [[ -d /oracle/abcadmin/lost+found ]]
>the file /oracle/abcadmin/lost+found was not found due to which the script failed.

That's strange, ksh says:
-d file True if file exists and is a directory.

So this should fall into your final exit.