天天看點

Linux/UNIX環境下Oracle資料庫多執行個體開機啟動腳本(轉)

作業系統平台:RHEL 5

Shell環境:Bash

Oracle:10g2

功能描述:開機時自動切換到oracle使用者下,啟動oracle的多個執行個體。并記錄資料庫的啟動情況到自定義的日志檔案中。

#!/bin/bash

LOG_PATH=$HOME/oracle_initing.log

log() {

if [ $# -lt 1 -a $# -gt 1 ];then

exit 5

fi

case "$@" in

success)

echo `date +%b" "%d" "%T`" "$PRO": Oracle instence \"$ORACLE_SID\" starting up succefully" >> $LOG_PATH;;

failed)

echo `date +%b" "%d" "%T`" "$PRO": Oracle instence \"$ORACLE_SID\" starting up FAILED" >> $LOG_PATH;;

*)

echo `date +%b" "%d" "%T`" "$PRO": "$@ >> $LOG_PATH;;

esac

}

lsstart() {

# stop stopping

# start starting

lsnrctl >> $LOG_PATH <<EOF

status

start

exit

EOF

init_oracle() {

#lsstart stop the listen

# lsstart

HOSTNAME=`hostname |awk -F. '{print $1}'`

PRO=$0

ORACLE_SIDS=`sed -rn '/^([^#].*):/!d;p' /etc/oratab |awk -F: '{printf $1" "}'`

if [ -z "$ORACLE_SIDS" ] ;then

exit 2

else

echo $ORACLE_SIDS

for ORACLE_SID in $ORACLE_SIDS

do

# echo $ORACLE_SID

#start or stop the oracle databases

# startup

# shutdown immediate

if sqlplus -S /nolog >> $LOG_PATH <<EOF

conn / as sysdba

startup

then

log success

continue

log failed

exit 3

done

if [ $"$UID" -eq 0 ] ;then

su - oracle

init_oracle

#lsstart start the listen

exit 0

elif [ "$USER" = "oracle" ] ;then

exit 4

http://wangxiaoyu.blog.51cto.com/922065/197630