将Oracle数据库设为Linux系统服务,并使其能随系统启动和关闭数据库。
1. vi /etc/oratab
#!/bin/bash
#chkconfig: 2345 20 80
#description: Oracle dbstart/dbshut
#/etc/rc.d/init.d/oracle
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
ORACLE_OWNER=oracle
LOGFILE=/var/log/oracle.log
DATE=`date +%Y-%m-%d`
echo "################################">>${LOGFILE}
echo "## Run Oracle "${DATE} >> ${LOGFILE}
if [! -f ${ORACLE_HOME}"/bin/dbstart" ] || [ ! -f ${ORACLE_HOME}"/bin/dbshut" ]; then
echo "ERROR: Missing the script file "${ORACLE_HOME}"/bin/dbstart or "${ORACLE_HOME}"/bin/dbshut!">>${LOGFILE}
echo "################################">>${LOGFILE}
exit
fi
start(){
touch /var/lock/subsys/oracle
echo "###Startup oracle....."
su - ${ORACLE_OWNER} -c ${ORACLE_HOME}"/bin/lsnrctl start"
su - ${ORACLE_OWNER} -c ${ORACLE_HOME}"/bin/dbstart "${ORACLE_HOME}
echo "###Done"
#echo "###Run database control......"
#su - ${ORACLE_OWNER} -c ${ORACLE_HOME}"/bin/emctl start dbconsole"
echo "###Done"
echo "###startup oracle successful....."
}
stop(){
#echo "###Stop database control......"
#su - ${ORACLE_OWNER} -c ${ORACLE_HOME}"/bin/emctl stop dbconsole"
echo "###Done"
echo "###Shutdown oracle------"
su - ${ORACLE_OWNER} -c ${ORACLE_HOME}"/bin/lsnrctl stop"
su - ${ORACLE_OWNER} -c ${ORACLE_HOME}"/bin/dbshut "${ORACLE_HOME}
echo "###Done"
rm -f /var/lock/subsys/oracle
echo "###Shutdown oracle successful-------"
}
case "$1" in
‘start‘)
start >> ${LOGFILE}
;;
‘stop‘)
stop >> ${LOGFILE}
;;
‘restart‘)
stop >> ${LOGFILE}
start >> ${LOGFILE}
;;
*)
echo "Usage:`basename $0` start|stop|restart"
exit 1
esac
echo "###Finished.">>${LOGFILE}
echo "################################">>${LOGFILE}
exit 0BLOG: http://blog.csdn.net/xcl168
原文:http://blog.csdn.net/slience_perseverance/article/details/19844759