Database startup/shutdown UNIX script

This Unix script will startup or shutdown a particular Oracle database.

Our development environment has over 10 databases active at one time. This script will start or shut down a particular database.

Here's the syntax:

sd the_database "shutdown abort" /var/opt/oracle/oratab 

or 

sd the_database "startup" /var/opt/oracle/oratab 

You can change the script to hard code the path to your oratab. It also assumes only two Oracle homes are to be found in oratab -- an 8.1.6 OR 8.1.7, and 7.3 (or other.) Further modifications are required to handle 8.1.6 AND 8.1.7! I use this script to schedule databases to start/stop via crontab.

                
#!/usr/bin/ksh 
#  sd - start database  or stop database 
#  sd takes three parameters 
#  1) sid 
#  2) what to do, ex: 
#      "startup mount" 
#      "startup" 
#      "shutdown immediate" 
#      "shutdown abort" 
#       etc. 
#   3) path to oratab file  ex:  /var/opt/oracle/oratab 
#   for ease, you may want to hardcode the path and eliminate the 3rd parameter 
# 
#  example:  sd my_database "shutdown abort" /var/opt/oracle/oratab 
# 
#  assumes only two environments 8.1 and 7.3 if you have more 
#  than one environment or you have 8.1.6 and 8.1.7, further 
#  changes must be made. 

#if [ -z "$*" ] || [ $# -lt 2 ] 
if [ -z "$*" ] || [ $# -lt 3 ] 
then 
  echo "USAGE: $0 sid startup or "shutdown abort"" 
else 
dowhat=$2 
ORACLE_SID=$1 
echo $ORACLE_SID 
doalter='alter system switch logfile;' 
notfound='TRUE' 
#if [ "$dowhat" = "startup" ] 
if  expr "$dowhat" : "startup" 
then 
doalter='REM;' 
fi 
# if you go with only two parameters, comment out the next line 
# and uncomment/set the oratab=path_to/oratab 
ORATAB=$3 
# change this to where your oratab file is located. 
# ORATAB=/etc/oratab 
# ORATAB=/var/opt/oracle/oratab 
echo $dowhat 
cat $ORATAB | while read LINE 
do 
 case $LINE in 
        #*)            ;;      #comment-line in oratab 
        *) 
            if [ "`echo $LINE | awk -F: '{print $1}' -`" = "$ORACLE_SID" ] ; then 
            if  expr "`echo $LINE | awk -F: '{print $2}' -`" : "8.1"  ; then 
             v="`echo $LINE | awk -F: '{print $2}' -`" 
             export ORACLE_BASE=$v 
             ORACLE_BASE=$v 
             echo "nORACLE_BASE=$v" 
             export ORACLE_HOME=$v 
             ORACLE_HOME=$v 
             echo "nORACLE_HOME=$v" 
             export JAVA_HOME=$v/jre/1.1.8 
             JAVA_HOME=$v/jre/1.1.8 
             echo "nJAVA_HOME=$v/jre/1.1.8" 
             export JRECLASSPATH=$v/jre/1.1.8:$v/jdbc/lib 
             JRECLASSPATH=$v/jre/1.1.8:$v/jdbc/lib 
             echo "nCLASSPATH=$v/jre/1.1.8:$v/jdbc/lib" 
             export ORACLE_SID=$1 
             ORACLE_SID=$1 
             echo "nORACLE_SID=$1" 
             export LD_LIBRARY_PATH=$v/lib:$v/javavm/lib:$v/jlib:$v/network/lib:$v/jdbc/lib 
             LD_LIBRARY_PATH=$v/lib:$v/javavm/lib:$v/jlib:$v/network/lib:$v/jdbc/lib 
             echo "nLD_LIBRARY_PATH=$v/lib:$v/javavm/lib:$v/network/lib" 
             export LIBPATH=$v/lib:$v/jlib:$v/javavm/lib:$v/network/lib 
             LIBPATH=$v/lib:$v/jlib:$v/javavm/lib:$v/network/lib 
             echo "nLIBPATH=$v/lib:$v/javavm/lib:$v/network/lib" 
             export CLASSPATH=.:$v/jdbc/lib/classes111.zip:$v/lib:$v/jlib:$v/jlib/javax-ssl_1.2.jar:$v/jlib/jssl-1_2.jar:$v/javavm/l

ib/aurora.zip:$v/lib/vbjapp.jar:$v/lib/vbjorb.jar 
             CLASSPATH=.:$v/jdbc/lib/classes111.zip:$v/lib:$v/jlib:$v/jlib/javax-ssl_1.2.jar:$v/jlib/jssl-1_2.jar:$v/javavm/lib/auro

ra.zip:$v/lib/vbjapp.jar:$v/lib/vbjorb.jar 
             echo "nCLASSPATH=$v/jlib/javax-ssl_1.2.jar:$v/jlib/jssl-1_2.jar:$v/javavm/lib/aurora.zip:$v/javavm/lib:/$v/lib:$v/lib/

vbjapp.jar:$v/lib/vbjorb.jar:$v/jdbc/lib/classes111.zip:." 
             export PATH=.:$HOME/bin:$v/bin:/bin:/usr/bin:/usr/lbin:/usr/ucb:/etc:$v/jre/1.1.8/bin 
             PATH=.:$HOME/bin:$v/bin:/bin:/usr/bin:/usr/lbin:/usr/ucb:/etc:$v/jre/1.1.8/bin 
             echo "nPATH=.:$HOME/bin:$v/bin:/bin:/usr/bin:/usr/lbin:/usr/ucb:/etc:n" 
notfound='FALSE' 
sqlplus -restrict 3  /nolog  << EOF 
connect internal 
$doalter 
$dowhat 
EOF 
else 
             v="`echo $LINE | awk -F: '{print $2}' -`" 
             export ORACLE_BASE=$v 
             ORACLE_BASE=$v 
             echo "nORACLE_BASE=$v" 
             export ORACLE_HOME=$v 
             ORACLE_HOME=$v 
             echo "nORACLE_HOME=$v" 
             export PATH=.:$HOME/bin:$v/bin:/bin:/usr/bin:/usr/lbin:/usr/ucb:/etc: 
             PATH=.:$HOME/bin:$v/bin:/bin:/usr/bin:/usr/lbin:/usr/ucb:/etc: 
             echo "nPATH=.:$HOME/bin:$v/bin:/bin:/usr/bin:/usr/lbin:/usr/ucb:/etc:n" 
             export ORACLE_SID=$1  
             ORACLE_SID=$1  
notfound='FALSE' 
svrmgrl << EOF 
connect internal 
$doalter 
$dowhat 
EOF 
fi 
fi 
esac 
done 
if [ $notfound = 'TRUE' ] 
then 
echo "$ORACLE_SID was not found" 
fi 
fi 

For More Information

  • What do you think about this tip? E-mail the Editor at tdichiara@techtarget.com with your feedback.
  • The Best Oracle Web Links: tips, tutorials, scripts, and more.
  • Have an Oracle tip to offer your fellow DBA's and developers? The best tips submitted will receive a cool prize--submit your tip today!
  • Ask your technical Oracle questions--or help out your peers by answering them--in our live discussion forums.
  • Check out our Ask the Experts feature: Our SQL, database design, Oracle, SQL Server, DB2, metadata, and data warehousing gurus are waiting to answer your toughest questions.

This was first published in March 2002

Dig deeper on Oracle and SQL

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close