本文共 3005 字,大约阅读时间需要 10 分钟。
#!/bin/bash ############################################################## # Script to startup and shutdown Oracle and listener # Author: neo - http://netkiller.8800.org # File:/etc/rc.d/init.d/oracle # chmod 750 /etc/init.d/oracle # chkconfig --add oracle --level 0356 ############################################################## # Setup environment for script execution export ORACLE_BASE=/u01/app/oracle export ORACLE_HOME=/u01/app/oracle/product/10.2.0.1/ export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/Apache/Apache/bin:$PATH export NLS_LANG='croatian_croatia.ee8iso8859p2' export ORACLE_SID=orcl export DISPLAY=:0 export USER=oracle if [ -f ./home/oracle/.bash_profile ]; then ./home/oracle/.bash_profile fi # Determine and execute action based on command line parameter # 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 } function isql { case "$1" in start) echo "*** Starting Oracle iSQL Plus *** " su - $USER -c "$ORACLE_HOME/bin/isqlplusctl start" echo "*** Note: You can access service at url: http://$(hostname):5560/isqlplus" ;; stop) echo "*** Stopping Oracle iSQL Plus *** " su - $USER -c "$ORACLE_HOME/bin/isqlplusctl stop" ;; *) echo "Usage: $1 isql {start|stop}" ;; esac } function sqlplus { case "$1" in start) su - "$oracle_user"<<EOO lsnrctl start apachectl start sqlplus /nolog<<EOS connect / as sysdba startup EOS EOO ;; stop) su - "$oracle_user"<<EOO lsnrctl stop apachectl stop sqlplus /nolog<<EOS connect / as sysdba shutdown immediate EOS EOO ;; *) echo "Usage: $1 emctl {start|stop}" ;; esac } function emctl { case "$1" in start) echo "*** Starting Oracle Enterprise Manager 10g Database Control ***" su - $USER -c "$ORACLE_HOME/bin/emctl start dbconsole" echo "*** Note: You can access service at url: http://$(hostname):1158/em" ;; stop) echo "*** Stopping Oracle Enterprise Manager 10g Database Control ***" su - $USER -c "$ORACLE_HOME/bin/emctl stop dbconsole" ;; *) echo "Usage: $1 emctl {start|stop}" ;; esac } case "$1" in start) echo "Starting Oracle database(s) listed in /etc/oratab ..." sleep 2 su - $USER -c "$ORACLE_HOME/bin/dbstart" echo "Starting TNS listener ..." sleep 2 su - $USER -c "$ORACLE_HOME/bin/lsnrctl start" touch /var/lock/subsys/orcl ;; stop) echo "Shutting down TNS listener ..." sleep 2 su - $USER -c "$ORACLE_HOME/bin/lsnrctl stop" echo "Shutting down Oracle database(s) listed in /etc/oratab ..." su - $USER -c "$ORACLE_HOME/bin/dbshut" rm -f /var/lock/subsys/orcl ;; status) chkdb_status ps -ax | grep -e ora_ -e tnslsnr ;; isql) isql $2 ;; sqlplus) sqlplus $2 ;; emctl) emctl $2 ;; *) echo "Usage: $1 {start|stop|status}" echo echo "Usage: $1 [isql | sqlplus | emctl] {start|stop}" ;; esac exit 0 原文出处:Netkiller 系列 手札 本文作者:陈景峯 转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。