Home > dba_scripts > script to shutdown single instance oracle database

script to shutdown single instance oracle database

#!/bin/ksh
#——————————————————————
# name : oradbshut.ksh
# This script is used to shudown oracle database
# Arguments $1 = ORACLE_SID(Required)
# Argument $2 = normal, immediate, abort(optional)
# If argument 2 is not specified then default normal
# usage: orashutdb.ksh <ora sid> [<shutdown type>]
#       Created By : Uma M Katru
#       Date : 07-08-2010
#——————————————————————-
dbshutUsage()
{
printf “\nError: $Me – incorrect number of arguments!\n\n”
printf “Usage: $Me <ora sid> [normal | immediate | abort].\n\n”
printf “where:\n\n”
printf ”  <ora sid>   : is the unique oracle instance identifier to shutdown non rac and rac instance on the local node required.\n”
printf ”   [<shutdown type>]      : shutdown type (Valid shutdown arguments are:  normal, immediate, abort.\n”
printf “examples:\n”
printf ”  $Me oradv1  — shutdown oracle database in normal mode\n”
printf ”  $Me oradv1 immediate — shutdown oracle database immediately\n”
exit 1
}
#############################################################################
# $1 is the actual message to log
# —————————————————————————–
upLog()
{
\echo “$1”
}
# —————————————————————————–
# main
#—————————————————————————–
Me=$(\basename $0)
mypath=$(\dirname $0)
export ORACLE_BASE=/u01/app/oracle
#set -vx

args=$#
if [[ $args = 1 ]]; then
ORACLE_SID=$1
SHUTMODE=normal
elif [[ $args = 2 ]];then
ORACLE_SID=$1
SHUTMODE=$2
else
dbshutUsage
fi

#check sid exists in oratab
sidexists=$(grep -i “^$ORACLE_SID:” /etc/oratab |wc -l | awk ‘{print $1}’)
if [[ $sidexists -eq 1 ]];then
echo
ORACLE_HOME=$(grep -w ^”$ORACLE_SID” /etc/oratab | awk -F”:” ‘{print $2}’)
else
echo “oracle instance is not available  on this machine”
exit 1
fi

#Check if db is running or not
ChekDBRunning=`ps -ef | grep -v grep | grep ora_.*_${ORACLE_SID} | wc -l`
if [ $ChekDBRunning -lt 1 ]; then
echo “Error: Database $ORACLE_SID is not up, shutdown not performed.”
exit 0
fi
LogDir=/home/oracle/admin/logs/$ORACLE_SID
if [[ ! -d /home/oracle/admin/logs/$ORACLE_SID ]];then
mkdir -p /home/oracle/admin/logs/$ORACLE_SID
fi
logFile=$LogDir/$(\echo $Me | \awk -F. ‘{print $1}’)$ORACLE_SID.blog.$(\date +%Y%m%d)
export ORACLE_SID=$ORACLE_SID
export ORACLE_HOME=$ORACLE_HOME
upLog “$Me started @$(\date)”
upLog “ORACLE_BASE ………………:$ORACLE_BASE”
upLog “ORACLE_HOME ………………:$ORACLE_HOME”
upLog “DB_NAME ………………….:$ORACLE_SID”
upLog “CurrentTime ………………:`date`”
echo “Shutting down $ORACLE_SID … Please wait…”
$ORACLE_HOME/bin/sqlplus “/ as sysdba”  << ! >> $logFile
shutdown $SHUTARG
exit
!
if [[ $rc -eq 0 ]] ; then
echo “”
echo “$Me: Database $ORACLE_SID shutdown completed successfully.”
upLog “$Me finished @$(\date)”
echo “”
else
echo “”
echo “$Me: unable to shutdown $ORACLE_SID database instance,Please see log file for details.”
upLog “$Me failed to shutdown $ORACLE_SID @$(\date)”
exit 1
fi
echo “—————————————————————-” >> $logFile
exit 0

Sample output :

./oradbshut.ksh

Error: oradbshut.ksh – incorrect number of arguments!

Usage: oradbshut.ksh <ora sid> [normal | immediate | abort].

where:

<ora sid>   : is the unique oracle instance identifier to shutdown non rac and rac instance on the local node required.
[<shutdown type>]      : shutdown type (Valid shutdown arguments are:  normal, immediate, abort.
examples:
oradbshut.ksh oradv1  — shutdown oracle database in normal mode
oradbshut.ksh oradv1 immediate — shutdown oracle database immediately

=============

./oradbshut.ksh uk10205

Error: Database uk10205 is not up, shutdown not performed.

=================

./oradbshut.ksh uk10205

oradbshut.ksh started @Mon Jul 10 10:50:55 PDT 2011
ORACLE_BASE ………………:/u01/app/oracle
ORACLE_HOME ………………:/u01/app/oracle/product/10.2.0.5/db_1
DB_NAME ………………….:uk10205
CurrentTime ………………:Mon Jul 10 10:50:55 PDT 2011
Shutting down uk10205 … Please wait…

oradbshut.ksh: Database uk10205 shutdown completed successfully.
oradbshut.ksh finished @Mon Jul 10 10:51:01 PDT 2011

 

Advertisements
Categories: dba_scripts
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: