OraMatt: YABAOracle

Yet Another Blog About Oracle

Yet Another Oracle Init Script

I’ve used this script a bunch in the past for instance startup and when I’m only dealing with 1 ORACLE_HOME.

This new init script uses UNIX cat and cut to parse the /etc/oratab (linux only) to set the ORACLE_SID & ORACLE_HOME to startup up your instances.

ENJOY!


#!/bin/bash
#
# init script for starting, stoping, restarting Oracle
#
# Author: Matt D (mattdee@gmail.com)
# Created: 02.18.2014
#
#

# Install instructions
# 
# Place in /etc/init.d
# chgrp dba oractl
# chmod 750 oractl
# ln -s /etc/init.d/oractl /etc/rc0.d/K01oemora
# ln -s /etc/init.d/oractl /etc/rc3.d/S99oemora



# 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 lisenter
		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
		export ORACLE_SID=`echo $i | cut -d: -f1`
		export ORACLE_HOME=`echo $i | cut -d: -f2`
		su $ORA_OWNER -c "$ORACLE_HOME/bin/sqlplus / as sysdba <<EOF  
		startup;
		exit;
		EOF
		"
		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 | cut -d: -f1`
		export ORACLE_HOME=`echo $i | cut -d: -f2`
		su $ORA_OWNER -c "$ORACLE_HOME/bin/sqlplus / as sysdba <<EOF  
		shutdown immediate;
		exit;
		EOF
		"
		done
		# Stop the lisenter
		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

One response to “Yet Another Oracle Init Script”

  1. […] was reviewing my INIT script that I posted here and I noticed there was no respect if a SID was marked as NO in […]

Leave a comment

Navigation

About

I’m Matt and I do Oracle things.