Skip to content

Instantly share code, notes, and snippets.

@slamotte
Created March 29, 2011 19:47
Show Gist options
  • Save slamotte/893086 to your computer and use it in GitHub Desktop.
Save slamotte/893086 to your computer and use it in GitHub Desktop.
Script to start/stop Oracle under Unbuntu
#!/bin/bash
#
# Startup script for Oracle databases
export ORACLE_HOME=/opt/oracle/oracle/product/10.2.0/db_1
export PATH=$PATH:$ORACLE_HOME/bin
export TZ=CST6
function process_oem() {
egrep -v '^([:space:]*#|[:space:]*$)' /etc/oratab | egrep 'Y$' | sed "s/:.*//" | while read sid; do
echo "Processing Enterprise Manager for $sid"
export ORACLE_SID=$sid
su oracle -c "$ORACLE_HOME/bin/emctl $1 dbconsole > /dev/null &"
done
# Don't bother starting isqlplus, its been deprecated from 11g
#su oracle -c "$ORACLE_HOME/bin/isqlplusctl $1 > /dev/null &"
}
case "$1" in
start)
echo "Starting Oracle..."
su oracle -c $ORACLE_HOME/bin/dbstart
process_oem $1
touch /var/lock/oracle
echo "Done"
;;
stop)
echo "Stopping Oracle..."
su oracle -c $ORACLE_HOME/bin/dbshut
process_oem $1
rm -f /var/lock/oracle
echo "Done"
;;
*)
echo "Usage: '$0' start|stop"
exit 1
esac
exit 0
@slamotte
Copy link
Author

Save this as /etc/init.d/oracle and execute the following:

sudo chmod 755 /etc/init.d/oracle
sudo update-rc.d oracle defaults 99

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment