#!/bin/bash ORACLE_SID=${0##*-} #That's clever, isn't it? Requires ksh or bash, though. IFS=: while read SID HOME DBSTART do if [[ "$ORACLE_SID" == "$SID" ]] then ORACLE_HOME=${HOME} break fi done < /etc/oratab IFS='' start() { # Start the database su - oracle -c ' export ORACLE_SID='$ORACLE_SID' export ORACLE_HOME='$ORACLE_HOME' echo -e " connect / as sysdba \n startup \n quit \n " | $ORACLE_HOME/bin/sqlplus /nolog ' } stop() { su - oracle -c ' # Kill all non-local Oracle processes. export ORACLE_SID='$ORACLE_SID' export ORACLE_HOME='$ORACLE_HOME' pidstokill=$(ps ax | while read PID TTY STAT TIME COMMAND do if [[ "$COMMAND" == "oracle${ORACLE_SID} (LOCAL=NO)" ]] then echo $PID echo Killing $PID $COMMAND >&2 fi done ) if [[ ! -z "${pidstokill}" ]] then kill -ABRT ${pidstokill} fi # Shut down the database. #/home/oracle/OraHome1/bin/dbshut echo -e " connect / as sysdba \n shutdown immediate \n quit \n " | $ORACLE_HOME/bin/sqlplus /nolog ' } # See how we were called. case "$1" in start) start ;; stop) stop ;; restart) stop start ;; *) echo $"Usage: $0 {start|stop|restart}" exit 1 esac