自動啟動ORACLE Script Service

muxinqing發表於2015-05-08
All just to do better
一切只為了做的更好



SCRIPT NAME:oracle

#!/bin/bash
# chkconfig: 345 99 10
# description: script for the Oracle Instance, Listener
#
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you wish to execute dbstart and dbshut;
#
# Set ORA_OWNER to the user id of the owner of the
# Oracle database in ORA_HOME.
ORA_HOME=/app/oracle/product/11.2.0/db_1
ORA_OWNER=oracle
oracle_run=$(ps -ef|grep ora_dbw0_oracle11|grep -v grep|wc -l)
if [ ! -f $ORA_HOME/bin/dbstart ]
then
echo "Oracle startup: cannot start"
exit
fi
case "$1" in
'start')
# Start the Oracle databases:
# The following command assumes that the oracle login
# will not prompt the user for any values
#echo  "Starting Oracle Listeners: "
echo  -n "Starting Oracle Database ....."
su - oracle -c "$ORA_HOME/bin/lsnrctl start" >> /var/log/oracle.log
echo -n  "....."
sleep 1
echo "....."
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart"  >> /var/log/oracle.log  && echo  "(Succeed)" || echo  "(Failure)"
date +"! %T %a %D : Finished." >> /var/log/oracle
;;
'stop')
# Stop the Oracle databases:
# The following command assumes that the oracle login
# will not prompt the user for any values
#echo -n "Stoping Oracle Listeners: "
echo -n  "Stoping Oracle Database ....."
su - oracle -c "$ORA_HOME/bin/lsnrctl stop" >> /var/log/oracle.log
echo -n  "....."
sleep 1
echo "....."
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut" >> /var/log/oracle.log  && echo  "(Succeed)" || echo  "(Failure)"
date +"! %T %a %D : Finished." >> /var/log/oracle
;;
'restart')

echo  -n "Starting Oracle Database ....."
$0 stop >> /var/log/oracle.log  && echo  "(Succeed)" || echo  "(Failure)"


echo -n  "Stoping Oracle Database ....."
$0 start >> /var/log/oracle.log  && echo  "(Succeed)" || echo  "(Failure)"
;;
'status')
 if [ $oracle_run -eq 1 ]
oracle_status=$(su - $ORA_OWNER -c "$ORA_HOME/bin/sqlplus -silent / as sysdba" << mxq
set pagesize 0 feedback off verify off heading off echo off numwidth 4
select 'ORACLE STATUS: '||decode(status,'OPEN',' open runing','MOUNTED','oracle is mount runing','STARTED','oracle is nomount runing','oracle is stoping'),'ROLE: '||instance_role from v\$instance;
exit
mxq
)
echo $oracle_status
else
echo "oracle is stoping"
 fi
;;
esac




2、檔案修改成Y
etc/init.d/oracle
crds3db:/app/oracle/product/11.2.0/db_1:Y
3、新增服務
chkconfig --add oracle  #新增服務
chkconfig --level 345 oracle on  #345級別都啟用服務
chkconfig --list oracle #檢視服務
--chkconfig --del oracle  #刪除服務

4、啟動服務
新增服務服務後,不會立即啟動服務,如果需要立即啟動服務,需要執行
service oracle start #啟動服務
service oracle stop #停止服務
service oracle restart #重啟服務

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29065182/viewspace-1629523/,如需轉載,請註明出處,否則將追究法律責任。

相關文章