Shell script to invoke db startup/shutdown

Hi all,

I have a shell script which does db shutdown ..the script snippet which does this is as follows:

function call_sql_plus {
${SQLPLUS:-sqlplus} -s /nolog <<EOF
EXIT;
EOF
if [ $? -ne 0 ]
then
echo "Error occurred while calling sqlplus "
exit 2
fi
}

# Check for the Valid inputs
if [ "$1" = "" ] ; then
echo "ERROR: Invalid Input parameter"
echo "Usage: npdbstartstop.sh start/stop"
return
fi

# To set the Oracle variable, run the .profile
#su - ora10g
# Set the DB Conf details
echo "Set the ORACLE configurations"
. /software/np/db/scripts/dbenv.conf
echo $ORACLE_SID
if [ "$1" = "stop" ] ; then
echo "****** SHUTDOWN OPTION IS SELECTED... Connecting to DB..."
echo "****** SHUTDOWN OPTION SELECTED... ORACLE IS GOING DOWN IMMEDIATELY *********"
call_sql_plus
connect /as sysdba
shutdown immediate

---------------------------------------------------

all the oracle related env variables are set, including ORACLE_SID.
The problem with the above script is, it is getting into the sqlplus prompt and connecting as sysdba. But 'shutdown immediate' is not recognising as proper db shutdown command.

It is taking it as unix machine shutdown command.

Pls post ur valuable suggestions, how can i execute the above shell script in sqlplus context?

With Warm Regards,
Krishna

Why dont you again use "here document" method and fire it on sqlplus prompt.

  • nilesh

can u pls give me some example of that?

My requirement is that the, db shutdown should be invoked through executing shell script.

The commands are not being sent to sqlplus at all; you should use the same technique as in the call_sql_plus function using <<EOF to wrap the commands; this is called a "here document", as quick Googling for the term would have told you.