I wrote a script to shutdown the oracle database. The script works fine when I manually run the script. However, when i schedule a job, i get the following error.
Shutting Down cmismart ....................
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
SVR4 Error: 2: No such file or directory
HERE IS MY SCRIPT
#!/bin/ksh #Purpose: This script will shudown oracle.
###############################################################################
###Shutting down database
shutdown_db()
{
sqlplus -s / as sysdba <<END
WHENEVER SQLERROR EXIT FAILURE
set echo off newpage 0 space 0 pagesize 0 feed off head off
SHUTDOWN IMMEDIATE
END
return $?
}
touch $ERRLOG
echo "Shutting Down $ORACLE_SID ...................."
if shutdown_db
then
DBPROCESS=`ps -ef | grep ${ORACLE_SID} | grep pmon | wc -l`
if [ $DBPROCESS -eq 0 ]
then
echo "$ORACLE_SID has been successfully shutdown."
else
echo "$An error occured while trying to shutdown $ORACLE_SID" >> ./$ERRLOG
fi
else
echo "Error occured while shutting down $ORACLE_SID." >> ./$ERRLOG
fi
check the man page of crontab.This is what i got from net
Crontab Environment
___________
cron invokes the command from the user's HOME directory with the shell, (/usr/bin/sh).
cron supplies a default environment for every shell, defining:
HOME=user's-home-directory
LOGNAME=user's-login-id
PATH=/usr/bin:/usr/sbin:.
SHELL=/usr/bin/sh
Users who desire to have their .profile executed must explicitly do so in the crontab entry or in a script called by the entry.
Make sure that your cron is running as user "oracle" or from a root cron with syntax:
su - oracle -c "scriptname params".
See system supplied script ${ORACLE_HOME}/bin/dbshut and make sure that you have everything in your script to match your version of Oracle. The system script may not have "shutdown immediate" but otherwise all the elements should be there.
The system scripts positively set PATH rather than appending to the system PATH.
To find out your environment under cron try a single line cron containing say only "env >/tmp/env$$.txt" , then repeat this as from cron as user oracle.