操作系统平台:RHEL 5
Shell环境:Bash
Oracle:10g2

功能描述:开机时自动切换到oracle用户下,启动oracle的多个实例。并记录数据库的启动情况到自定义的日志文件中。

#!/bin/bash
# wang_xiaoyu@qq.com
# 2009-06-19 21:05:49
# 2009-06-19 22:54:24
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
EOF
     then
        log success
        continue
     else
        log failed
        exit 3
     fi
    done
fi
}
if [ $"$UID" -eq 0 ] ;then
su - oracle
init_oracle
#lsstart start the listen
# lsstart
exit 0
elif [ "$USER" = "oracle" ] ;then
init_oracle
#lsstart start the listen
# lsstart
exit 0
else
exit 4
fi