OraMatt: YABAOracle

Yet Another Blog About Oracle

, , ,

Improved Oracle INIT script

So….I was reviewing my INIT script that I posted here and I noticed there was no respect if a SID was marked as NO in /etc/oratab.

I’ve adjusted the script to now respect the startup status setting in oratab!!!

Enjoy!


#!/bin/bash
#
# init script for starting, stoping, restarting Oracle
#
# Author: Matt D (mattdee@gmail.com)
# Created: 02.18.2014
# Updated: 03.4.2014
#
#
# chkconfig: 123 69 68
# description: Oracle Startup Script 
#
# Install instructions
#
# Place in /etc/init.d
# chgrp dba oractl
# chmod 750 oractl
# ln -s /etc/init.d/oractl /etc/rc0.d/K01oractl
# ln -s /etc/init.d/oractl /etc/rc3.d/S99oractl
#
# Add to chkconfig
# chkconfig --add oractl
# chkconfig --level 12345 oractl on
#

# Set Environment
# Change based on site
export LISTENER_HOME=/u01/app/oracle/product/12.1.0/dbhome_1
export ORA_OWNER=oracle

export PATH=${PATH}:$ORACLE_HOME/bin

# Functions
function start_it()
 {
 echo "Starting Database Stack"
 echo "."
 # Start the listener
 export ORACLE_HOME=$LISTENER_HOME
 su $ORA_OWNER -c "$LISTENER_HOME/bin/lsnrctl start"
 # Get a list of the ORACLE_HOME & SID
 for i in `cat /etc/oratab`
 do
 unset ORACLE_SID
 unset ORACLE_HOME
 unset STARTUP
 export ORACLE_SID=`echo $i | grep -v \<| grep : |cut -d: -f1`
 export ORACLE_HOME=`echo $i | grep -v \<| grep :|cut -d: -f2`
 export STARTUP=`echo $i | grep -v \<| grep : |cut -d: -f3`
 if test "${STARTUP}" = Y
 then
 echo "Starting SID: "${ORACLE_SID}
 su $ORA_OWNER -c "$ORACLE_HOME/bin/sqlplus / as sysdba <<EOF
 startup;
 exit;
 EOF
 "
 else
 echo "SID is NOT marked to start!"
 fi
 done
 }

function stop_it()
 {
 echo "Stopping Database Stack"
 echo "."
 # Stop the database
 # Get a list of the ORACLE_HOME & SID
 for i in `cat /etc/oratab`
 do
 unset ORACLE_SID
 unset ORACLE_HOME
 export ORACLE_SID=`echo $i | grep -v \<| grep : |cut -d: -f1`
 export ORACLE_HOME=`echo $i | grep -v \<| grep :|cut -d: -f2`
 su $ORA_OWNER -c "$ORACLE_HOME/bin/sqlplus / as sysdba <<EOF
 shutdown immediate;
 exit;
 EOF
 "
 done
 # Stop the listener
 export ORACLE_HOME=$LISTENER_HOME
 su $ORA_OWNER -c "$LISTENER_HOME/bin/lsnrctl stop"
 }

case "$1" in
 start)
 start_it
 ;;
 stop)
 stop_it
 ;;
 restart)
 echo "Restarting Database Stack"
 echo "."
 stop_it
 start_it
 ;;
 *)
 echo "Usage: /etc/init.d/oractl start|stop|restart"
 exit 1
 ;;
esac


Leave a comment

Navigation

About

I’m Matt and I do Oracle things.