Run level shell script to start Oracle 10g services on RedHat Enterprise Linux (RHAS 4)

in Script

#!/bin/bash
#
# Run level script to start Oracle 10g services on RedHat Enterprise Linux (RHAS 4)
# Script should work on other UNIX like oses :)
# -------------------------------------------------------------------------
# Copyright (c) 2006 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# Comment/suggestion: <vivek at nixCraft DOT com>
# -------------------------------------------------------------------------
# chkconfig: 345 91 19
# description: Startup/Shutdown Oracle service
 
OUSER="oracle"
OPATH="/home/oracle/oracle/product/10.2.0/db_1"
 
# check Oracle db status
function chkdb_status() {
 
# set username
SUSER="scott"
# set password
SPASS="123456"
 
sqlplus -s /nolog > /dev/null 2>&1 <<EOF
whenever sqlerror exit failure
connect $SUSER/$SPASS
exit success
EOF
 
if [ $? -ne 0 ]; then
 echo "Connection failed : DB is down"
 exit 1
else
 echo "Connection succeeded : DB is up"
fi
}
 
case "$1" in
        start)
        echo  "*** Starting Oracle *** "
        su - $OUSER -c "$OPATH/bin/lsnrctl start"
        su - $OUSER -c "$OPATH/bin/dbstart"
        ;;
        stop)
        echo  "*** Stopping Oracle *** "
        su - $OUSER -c "$OPATH/bin/lsnrctl stop"
        su - $OUSER -c "$OPATH/bin/dbshut"
        ;;
        restart)
        $0 stop
        $1 start
        ;;
        isqlstart)
        echo  "*** Starting Oracle iSQL Plus *** "
        su - $OUSER -c "$OPATH/bin/isqlplusctl start"
        echo "*** Note: You can access service at url:  http://$(hostname):5560/isqlplus"
        ;;
        isqlstop)
        echo  "*** Stopping Oracle iSQL Plus *** "
        su - $OUSER -c "$OPATH/bin/isqlplusctl stop"
        ;;
        emstart)
        echo  "*** Starting Oracle Enterprise Manager 10g Database Control ***"
        su - $OUSER -c "$OPATH/bin/emctl start dbconsole"
        echo "*** Note: You can access service at url:  http://$(hostname):1158/em"
        ;;
        emstop)
        echo  "*** Stopping Oracle Enterprise Manager 10g Database Control ***"
        su - $OUSER -c "$OPATH/bin/emctl stop dbconsole"
        ;;
        status)
        echo "*** Oracle database status ***"
        chkdb_status
        ;;
        *)
        echo $"Usage: $0 {start|stop|isqlstart|isqlstop|emstart|emstop}"
        exit 1
esac
exit 0
Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our email newsletter to make sure you don't miss a single tip/tricks.

{ 1 trackback }

Step By Step Virtual PS Install: Install Database « PSST0101
October 30, 2008 at 11:19 am

{ 5 comments… read them below or add one }

Internetagentur August 4, 2008 at 11:19 am

Thank you … that tutorial has me very helped.

Reply

Thomas January 3, 2009 at 5:14 am

Thank you. Quite helpful. :)

Reply

seckin turk January 12, 2009 at 2:30 pm

COuld you please sendm me a mail?I want to ask you which editor did you use to paste this good looking code?

Is it html code ?

Reply

Nikhil April 15, 2009 at 12:50 pm

I am using oracle 10g through command line..It gives me following error while connecting. i am trying to connect as a dba..i am suse LINUX operating system…

SQL*PLUS:Release10.2.0.1.0- Production on Wed: Apr 15 17:26:27 2009

Copyright(c) 1982, 2005, Oracle. All Rights Reserved.

SQL> connect
Enter user-name:SYS
Enter password:123
ERROR:
ORA-01034: ORACLE not available.
ORA-27121: unable to determine the size of share memory segment.
Linux Error:13:Permission Denied

kindly suggest me what to do?

Reply

WilliamG June 9, 2009 at 6:07 pm

Hi Nikhil, I had the same problem.
I settled with the following instructions

pront > sqlplus /nolog
SQL>connect / as sysdba
SQL>startup
SQL>quit

pront> cd $ORACLE_HOME/bin
pront> lsnrctl start

Reply

Leave a Comment

Previous post: Shell Script accept password using read commnad

Next post: Shell Script to start DLink PCL wireless lan card 520 / 510