Operating System - HP-UX
1833006 Members
3034 Online
110048 Solutions
New Discussion

Re: rc=2 error on cron job

 
Victor_138
Regular Advisor

rc=2 error on cron job

I have added 2 cron jobs to stop and start Oracle. After verifing the cron log I noticed that both jobs had returned an rc=2 code. After searching the forums I learned that anything other than rc=0 is an error.

Can someone explain to me what I'm doing wrong or what rc=2 means?

This is what's on the cron log:

> CMD: su - oracle -c /u01/dba/oracle/product/7.3.4/bin/dbshut
> oracle 14462 c Wed May 25 23:00:00 SAT 2005
< oracle 14462 c Wed May 25 23:00:01 SAT 2005 rc=2
> CMD: su - oracle -c /u01/dba/oracle/product/7.3.4/bin/dbstart
> oracle 14719 c Thu May 26 05:00:00 SAT 2005
< oracle 14719 c Thu May 26 05:00:01 SAT 2005 rc=2

This is how the scripts look like,

dbshut:
#
# $Header: dbshut.sh.pp 07-may-97.12:04:34 mdenney Exp $ dbshut.sh.pp Copyr (c)
1991 Oracle
#

###################################
#
# usage: dbshut
#
# This script is used to shutdown ORACLE from /etc/rc(.local).
# It should ONLY be executed as part of the system boot procedure.
#
#####################################

ORATAB=/etc/oratab

trap 'exit' 1 2 3
case $ORACLE_TRACE in
T) set -x ;;
esac

# Set path if path not set (if called from /etc/rc)
case $PATH in
"") PATH=/bin:/usr/bin:/etc
export PATH ;;
esac

#
# Loop for every entry in oratab file and and try to start
# that ORACLE
#

cat $ORATAB | while read LINE
do
case $LINE in
\#*) ;; #comment-line in oratab
*)
# Proceed only if third field is 'Y'.
if [ "`echo $LINE | awk -F: '{print $3}' -`" = "Y" ] ; then
ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`
if [ "$ORACLE_SID" = '*' ] ; then
ORACLE_SID=""
fi
# Called programs use same database ID
export ORACLE_SID
ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -`
# Called scripts use same home directory
export ORACLE_HOME
# Put $ORACLE_HOME/bin into PATH and export.
PATH=$ORACLE_HOME/bin:/bin:/usr/bin:/etc ; export PATH

PFILE=${ORACLE_HOME}/dbs/init${ORACLE_SID}.ora

lsnrctl stop

# See if it is a V6 or V7 database
if test -f $ORACLE_HOME/bin/svrmgrl; then
svrmgrl << EOF
connect internal
shutdown
EOF
else
if test -f $ORACLE_HOME/bin/sqldba; then
VERSION=`$ORACLE_HOME/bin/sqldba command=exit | awk '
/SQL\*DBA: (Release|Version)/ {split($3, V, ".") ;
print V[1]}'`

case $VERSION in
6) sqldba command=shutdown
;;

7) sqldba <connect internal
shutdown
EOF
;;
esac
else
echo "No SQL*DBA or svrmgrl found in $ORACLE_HOME"
fi
fi

if test $? -eq 0 ; then
echo "Database \"${ORACLE_SID}\" shut down."
else
echo "Database \"${ORACLE_SID}\" not shut down."
fi
fi
;;
esac
done

dbstart:
#
# $Header: dbstart.sh.pp 1.1 95/02/22 14:37:29 rdhoopar Osd $ dbstart.sh.p
p Copyr (c) 1991 Oracle
#

###################################
#
# usage: dbstart
#
# This script is used to start ORACLE from /etc/rc(.local).
# It should ONLY be executed as part of the system boot procedure.
#
#####################################

ORATAB=/etc/oratab

trap 'exit' 1 2 3
case $ORACLE_TRACE in
T) set -x ;;
esac

# Set path if path not set (if called from /etc/rc)
case $PATH in
"") PATH=/bin:/usr/bin:/etc
export PATH ;;
esac

#
# Loop for every entry in oratab file and and try to start
# that ORACLE
#

cat $ORATAB | while read LINE
do
case $LINE in
\#*) ;; #comment-line in oratab
*)
# Proceed only if third field is 'Y'.
if [ "`echo $LINE | awk -F: '{print $3}' -`" = "Y" ] ; then
ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`
if [ "$ORACLE_SID" = '*' ] ; then
ORACLE_SID=""
fi
# Called programs use same database ID
export ORACLE_SID
ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -`
# Called scripts use same home directory
export ORACLE_HOME
# Put $ORACLE_HOME/bin into PATH and export.
PATH=$ORACLE_HOME/bin:/bin:/usr/bin:/etc ; export PATH

PFILE=${ORACLE_HOME}/dbs/init${ORACLE_SID}.ora

# Figure out if this is a V5, V6, or V7 database. Do we really need V5?
if [ -f $ORACLE_HOME/bin/sqldba ] ; then
VERSION=`$ORACLE_HOME/bin/sqldba command=exit | awk '
/SQL\*DBA: (Release|Version)/ {split($3, V, ".") ;
print V[1]}'`
else
if test -f $ORACLE_HOME/bin/svrmgrl; then
VERSION="7.3"

else
VERSION="5"
fi
fi

if test -f $ORACLE_HOME/dbs/sgadef${ORACLE_SID}.dbf -o \
-f $ORACLE_HOME/dbs/sgadef${ORACLE_SID}.ora
then
STATUS="-1"
else
STATUS=1
fi
case $STATUS in
1) if [ -f $PFILE ] ; then
case $VERSION in
5) ior w pfile=$PFILE
;;

6) sqldba command=startup
;;

7) sqldba <connect internal
startup
EOF
;;

7.3) svrmgrl <connect internal
startup
EOF
;;
esac

if test $? -eq 0 ; then
echo ""
echo "Database \"${ORACLE_SID}\" warm started."
else
echo ""
echo "Database \"${ORACLE_SID}\" NOT started."
fi
else
echo ""
echo "Can't find init file for Database \"${ORACLE_SID}\
"."
echo "Database \"${ORACLE_SID}\" NOT started."
fi
;;

-1) echo ""
echo "Database \"${ORACLE_SID}\" possibly left running when
system went down (system crash?)."
echo "Notify Database Administrator."
case $VERSION in
5) ior c
;;

6) sqldba "command=shutdown abort"
;;

7) sqldba <connect internal
shutdown abort
EOF
;;

7.3) svrmgrl <connect internal
shutdown abort
EOF
;;
esac

if test $? -eq 0 ; then
if [ -f $PFILE ] ; then
case $VERSION in
5) ior w pfile=$PFILE
;;

6) sqldba command=startup
;;

7) sqldba <connect internal
startup
EOF
;;
7.3) svrmgrl <connect internal
startup
EOF
;;
esac
if test $? -eq 0 ; then
echo ""
echo "Database \"${ORACLE_SID}\" warm started."
else
echo ""
echo "Database \"${ORACLE_SID}\" NOT started."
fi
else
echo ""
echo "Can't find init file for Database \"${ORACLE_S
ID}\"."
echo "Database \"${ORACLE_SID}\" NOT started."
fi
else
echo "Database \"${ORACLE_SID}\" NOT started."
fi
;;
esac
fi
;;
esac
lsnrctl start
done
14 REPLIES 14
Doug O'Leary
Honored Contributor

Re: rc=2 error on cron job

Hey;

Those return codes are coming from the Oracle supplied dbstar/stop scripts - not from your cron entries. Your best bet would be to examine the oracle alert log to find out if there's anything amiss going on there. Failing that, a message to comp.databases.oracle.misc would probably get you better support than from the HP forum.

HTH;

Doug

------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
RAC_1
Honored Contributor

Re: rc=2 error on cron job

Did your script work?? (through cron)
cron scripts run with a very minimal environment.
You should be putting all required variables in your script itself.

Do the scripts run fine manually??

Anil
There is no substitute to HARDWORK
Steven E. Protter
Exalted Contributor

Re: rc=2 error on cron job

Does the database stop/start as commanded?

If so, the error is not something you need to worry about. If not, you probably have an environment problem.

If the script works from the command line and not cron then the environment shown by the env command is different and Oracle doesn't like it.

I found the dbshut command so ineffective, because it doesn't do a shutdown immediate, I re-wrote it and replaced it. My replacement always seemed to get a non-zero return code. The good news is it shut the database so I was happy and moved on to other issues.

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
Victor_138
Regular Advisor

Re: rc=2 error on cron job

Manually the scripts work perfectly.

How can I verify that they ran indeed?
Muthukumar_5
Honored Contributor

Re: rc=2 error on cron job

Run script in debug mode and redirect log information into a log file.

#!/bin/ksh
set -x
# dbshut.sh
... code
..
# set +x

In cron,
x x x x x script 1>/tmp/dbshut.log 2>&1

Check /tmp/dbshut.log file.

hth.
Easy to suggest when don't know about the problem!
Steven E. Protter
Exalted Contributor

Re: rc=2 error on cron job

In addition to the last set -x advice.

env > /tmp/$$.txt

After a cron run and a command line run.

cd /tmp

ls *.txt

diff the two files.

When the environment is the same, it will work the same in cron as the command line. Don't be afraid to set the TERM variable. Oracle is very sensitive about environment.

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
Cem Tugrul
Esteemed Contributor

Re: rc=2 error on cron job

Victor,

i had a similar problem as your few months
ago on my DP5.0 post&pre execution scripts
for to purpose Automated offline bcks and
i needed to shutdown&statup my ORacle 9i...
Normally my scripts were working from command
but when i have put these scripts from DP omniback onto pre-exec,post-exec then
failed so i discovered that i did not define
my env settings in these script like;
#!/usr/bin/ksh
ORACLE_HOME=/oracle/9.2.0
export ORACLE_USER=oracle
PATH=${ORACLE_HOME}/bin:/sbin:/usr/bin:/usr/sbin:/etc:/bin
export ORACLE_HOME

When i have put then it worked...

Good Luck,
Our greatest duty in this life is to help others. And please, if you can't
Victor_138
Regular Advisor

Re: rc=2 error on cron job

What does this #!/usr/bin/ksh do?

Victor BERRIDGE
Honored Contributor

Re: rc=2 error on cron job

Hi Victor,
Its calling a Kornshell to execute your script...


All the best
Victor
TwoProc
Honored Contributor

Re: rc=2 error on cron job

That #!/usr/bin/ksh tells the system to run ksh instead of whatever shell you were currently in (even if was ksh already) for entire contents of the commands in the script contained below.
We are the people our parents warned us about --Jimmy Buffett
Victor_138
Regular Advisor

Re: rc=2 error on cron job

Submitted this at job to see what happens

kcspecdp # at -f /u01/dba/oracle/product/7.3.4/bin/dbshut 1530
warning: commands will be executed using /usr/bin/sh
job 1117137600.a at Thu May 26 15:30:00 2005

Will at be "similar" to cron in terms of being able to watch what happens?
Greg Vaidman
Respected Contributor

Re: rc=2 error on cron job

at is different from cron in that it inherits the environment at the time you create the at job, whereas cron starts with a base environment. you can also see which at jobs are scheduled by running "at -l" and cancel jobs before they start with "at -r ".

in terms of monitoring at jobs, they are logged in the same cron log and will send output via email in exactly the same way a cron job would.
Victor_138
Regular Advisor

Re: rc=2 error on cron job

at ran and the script executed fine. Did noticed that some Oracle "errors" showed up but were regarding turning off or on the listener when it was already on or off.

Other than that seems to be working fine.

Thanks all
Victor BERRIDGE
Honored Contributor

Re: rc=2 error on cron job

Hi Victor,
In this case, write yourself a script or check your equivalent start/stop script that should be in /sbin/init.d
Lets say rc.oracle...
This is what I have in one of my 10.20 rc.oracle :
#!/usr/bin/ksh
export ORACTI_EXPLOIT=/opt/oracle/admin/exploit
export PATH=$PATH:/usr/bin:$ORACTI_EXPLOIT/proc


case "$1" in
start_msg)
echo "Start Oracle"
;;
stop_msg)
echo "Stop Oracle"
;;
start)
$ORACTI_EXPLOIT/proc/db_start
su - oracle -c $ORACTI_EXPLOIT/proc/net_start
;;
stop)
su - oracle -c $ORACTI_EXPLOIT/proc/net_stop
$ORACTI_EXPLOIT/proc/db_shut
;;
*)
echo "usage: $0 {start|stop}"
#rval=1
;;
esac
#End

Motice that this script start AND stops the listener also, so do the same
Now if this script does exactly what you want , then use it in your cronfile:
00 21 * * * /sbin/init.d/rc.oracle stop>>/sm/cron/log/cron_oracle.log 2>&1
00 05 * * * /sbin/init.d/rc.oracle start >>/sm/cron/log/cron_oracle.log 2>&1

I have created on most system here a separate filesystem: /sm with loads of sub like cron bin logs depot doc where is kept all that I believe is important for the sysadmins...
Here you would have now in /sm/cron/log the output from your cron execution so the information is quickly accessible without big search...

The problem will arise if you have more than on instance though... (Youve stopped the listener remember?...)

Now I wrote all this I have under my eyes maybe an explanation:
Someone will need to confirm (Still wearing bad glasses..)
At the end of your script:
...
.
.
else
echo "Database \"${ORACLE_SID}\" NOT started."
fi
;;
esac
fi
;;
esac
lsnrctl start #<--- You start the listener
done # But where do you stop it?....

So this script seems to work the first time but then at each call you may well have the listener still running... Explaining your error...


All the best
Victor