Skip navigation.

Saluting. Start - Stop script

David Lozano Lucas's picture

It is an English word that sounds very funny in Spanish, almost unreal.
Well, just wanted to brand the blog with a first entry to introduce myself.
I work as an Oracle and SQL Server DBA (mixed profile, they call it -
concerns twice for the same pay, on me).
Here I will write "how to" articles as they emerge in my day to day.
If you can read Spanish, check out the blog I maintain for a little more time http://blog.davidlozanolucas.com/.

Here is a script to start/stop Oracle databases running in Unix:

# ================================================================================================
#	Performs stop/start of instance (MYDB for this example).
# 	Parameters: 
#		1)  start  |   stop
#
#
# ================================================================================================
if [ $# -ne 1 ]; then
	exit 99
fi
accion=$1
export ORACLE_SID=MYDB

case "$accion" in 
'start')
sqlplus "/ as sysdba" <<HOLA
startup
HOLA

	tail -n 200 $ORACLE_BASE/admin/MYDB/bdump/alert_MYDB.log  > /tmp/backup_replica.alert.tmp 
	grep -i "Completed: ALTER DATABASE OPEN" /tmp/backup_replica.alert.tmp 
	cod1=$?
	grep -i "Starting ORACLE instance (normal)" /tmp/backup_replica.alert.tmp
	cod2=$?
	if [ $cod1 -ne 0 ] || [ $cod2 -ne 0 ]; then
		exit  1
	fi

# -------- LISTENER ---------
lsnrctl start LISTENER 
	if [ $? -ne 0 ]; then
		exit 2
	fi
	;;
'stop')
# -------- LISTENER ---------
lsnrctl stop LISTENER
        if [ $? -ne 0 ]; then
                exit 2
        fi
# -------  BASE DE DATOS ----
sqlplus "/ as sysdba" <<HOLA
shutdown immediate
HOLA

        tail -n 200 $ORACLE_BASE/admin/MYDB/bdump/alert_MYDB.log  > /tmp/backup_replica.alert.tmp
        grep -i "ALTER DATABASE DISMOUNT" /tmp/backup_replica.alert.tmp
        cod1=$?
        grep -i "Completed: ALTER DATABASE DISMOUNT"  /tmp/backup_replica.alert.tmp
        cod2=$?
	echo "cod1 $cod1 -- cod2 $cod2"
        if [ $cod1 -ne 0 ] || [ $cod2 -ne 0 ]; then
                exit  1
        fi
        ;;
*)
echo " " >/dev/null 2>&1
;;
esac
exit 0 
# ================================================================================================