Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
cancel
Showing results for 
Search instead for 
Did you mean: 

shutdown with timeout

SOLVED
Go to solution
Ryan Kogelheide
Frequent Advisor

shutdown with timeout

We had a network failure the other day on the link to one node of our two node OPS cluster. The node hang shutting down its instances and the other node's instances froze waiting for the first to finish. There can be any number of reasons why a shutdown immediate fails, but I thought I'd write a safer shutdown script. Unfortunately, it doesn't work.

#!/usr/bin/ksh
#-----------------------------------------------------------------------------
# Usage : shutdown.sh SID
# Description : shutdown the Oracle Instance for value given in SID
# This script is called by HP/MC packages
#
# stop the database service $1; if it's not dead
# in $2 seconds, kill the pmon process
#
# Execution : must be launched by Oracle User
#-----------------------------------------------------------------------------

if [ $# -lt 2 ] ; then
echo 'Usage: shutkill.sh "SID" "KILLWAIT"'
exit 1
fi

#
# Set the ORACLE_SID to $1 parameter and call oraenv utility to set
# ORACLE_HOME, PATH etc environment variables
# see oraenv utility for more informations
#

ORACLE_SID=$1; export ORACLE_SID
ORAENV_ASK=NO; export ORAENV_ASK
. oraenv

#
# calc process id of pmon
#
PMON=ps -ef | grep ora_pmon_$ORACLE_SID | grep -v grep | cut -c 9-17

#
# shutdown the "SID" instance
#

cat << EOF > $CMDFILE
connect / as sysdba
shutdown immediate
exit
EOF

sqlplus /nolog @$CMDFILE &
shutproc=$!

# check every 10 seconds to see if shutproc finished
waiting=0
sleep 10
while [[ "`ps -p $shutproc | grep -c .`" = 2 ]]; do
sleep 10
waiting=$((waiting+10));
if [[ $waiting -gt $1 ]]; then
echo Waited more than $1 ($waiting)
echo Error in shutdown, killing pmon proc
# kill $PMON
exit 72
fi
done


This proc returns:

sh: Syntax error: `(' is not expected.

Help oh generous brahmen!
2 REPLIES
Steve Steel
Honored Contributor
Solution

Re: shutdown with timeout

Hi

Put set -x as the second line of the script.

Will print the commands as they execute.

Then debug.

Suspect line.
echo Waited more than $1 ($waiting)

Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Ryan Kogelheide
Frequent Advisor

Re: shutdown with timeout

That worked... thanks duuude!