orarun – script automates database start, stop, status query tasks, also allows user to manage isqlplus console and em database control
Usage: orarun {start|stop|status|isqlstart|isqlstop|emstart|emstop}
Requirements: configured and working “dbstart” and “dbshut” scripts.
Installation:
Create “orarun” file and paste the code into the created file.
Make sure script’s location is in user’s $PATH (ex.: /home/oracle/bin/orarun)
[oracle@host bin]$ touch /home/oracle/bin/orarun; vi /home/oracle/bin/orarun
#paste the code and save changes (:wq)
#grand execute rights to the script
[oracle@host bin]$ chmod +x /home/oracle/bin/orarun
[oracle@host bin]$ orarun status
*** Oracle database status ***
Database: MY_DB1 is up and running
Enjoy the script…
#!/bin/sh #------------------------------------------------------------------------------------ # Script M. Izdebski v.1.1 (c) 2007-2010 # [email protected] # this script is dedicated for Oracle Enterprise Linux, # but schould work under other Linux; after minor modifications # This script is licensed under GNU GPL 2.0 or higer blablabla #-----------------------------------------------------------------------------------" #Veriables to set: ORA_USER="oracle" #ORA_PATH="/u01/app/oracle/product/10.2.0/db_1" #ORA_SID="sid" #or like this ORA_PATH=$ORACLE_HOME ORA_SID=$ORACLE_SID #Check user if oracle ORA_ID=`id -u $ORA_USER` if [ "`id -u`" != "$ORA_ID" ]; then echo "Script can only be executed by oracle user" ; exit fi #check Oracle DB status function chkdb_status() { check_proc=`ps -ef | grep ${ORA_SID} | grep pmon | wc -l`; oracle_num=`expr $check_proc` if [ $oracle_num -lt 1 ]; then echo echo "Database: $ORA_SID is down" echo else echo "Database: $ORA_SID is up and running" fi } case "$1" in start) echo "*** Starting Oracle *** " #if the listner has been set properly, will be started by the dbstart script #su - $ORA_USER -c "$ORA_PATH/bin/lsnrctl start" su - $ORA_USER -c "$ORA_PATH/bin/dbstart" chkdb_status ;; stop) echo "*** Stopping Oracle *** " #if the listner has been set properly, will be started by the dbshut script #su - $ORA_USER -c "$ORA_PATH/bin/lsnrctl stop" su - $ORA_USER -c "$ORA_PATH/bin/dbshut" chkdb_status ;; restart) $0 stop $1 start ;; isqlstart) echo "*** Starting Oracle iSQL Plus *** " su - $ORA_USER -c "$ORA_PATH/bin/isqlplusctl start" echo "********************************************************************" echo "*** Note: Access to service at http://$(hostname):5560/isqlplus" echo "********************************************************************" ;; isqlstop) echo "*** Stopping Oracle iSQL Plus *** " su - $ORA_USER -c "$ORA_PATH/bin/isqlplusctl stop" ;; emstart) echo "*** Starting Oracle Enterprise Manager 10g Database Control ***" su - $ORA_USER -c "$ORA_PATH/bin/emctl start dbconsole" echo "********************************************************************" echo "*** Note: Access to service at http://$(hostname):1158/em" echo "********************************************************************" ;; emstop) echo "*** Stopping Oracle Enterprise Manager 10g Database Control ***" su - $ORA_USER -c "$ORA_PATH/bin/emctl stop dbconsole" ;; status) echo "*** Oracle database status ***" chkdb_status ;; *) echo "Usage: {start|stop|status|isqlstart|isqlstop|emstart|emstop}" esac
Cheers!!