谁来写一个linux下开机启动oracle的脚本
2个回答
展开全部
以root身份建立开机启动oracle服务的脚本:vi /etc/init.d/oracle,添加如下脚本:
#!/bin/sh
#chkconfig: 2345 20 80
#description: Oracle dbstart / dbshut
#以上两行为chkconfig所需
ORA_HOME=/opt/oracle/11g
ORA_OWNER=oracle
LOGFILE=/var/log/oracle.log
echo "#################################" >> ${LOGFILE}
date +"### %T %a %D: Run Oracle" >> ${LOGFILE}
if [ ! -f ${ORA_HOME}/bin/dbstart ] || [ ! -f ${ORA_HOME}/bin/dbshut ]; then
echo "Error: Missing the script file ${ORA_HOME}/bin/dbstart or ${ORA_HOME}/bin/dbshut!" >> ${LOGFILE}
echo "#################################" >> ${LOGFILE}
exit
fi
start(){
echo "###Startup Database..."
su - ${ORA_OWNER} -c "${ORA_HOME}/bin/dbstart ${ORA_HOME}"
echo "###Done."
echo "###Run database control..."
su - ${ORA_OWNER} -c "${ORA_HOME}/bin/emctl start dbconsole"
echo "###Done."
}
stop(){
echo "###Stop database control..."
su - ${ORA_OWNER} -c "${ORA_HOME}/bin/emctl stop dbconsole"
echo "###Done."
echo "###Shutdown Database..."
su - ${ORA_OWNER} -c "${ORA_HOME}/bin/dbshut ${ORA_HOME}"
echo "###Done."
}
case "$1" in
'start')
start >> ${LOGFILE}
'stop')
stop >> ${LOGFILE}
'restart')
stop >> ${LOGFILE}
start >> ${LOGFILE}
esac
date +"### %T %a %D: Finished." >> ${LOGFILE}
echo "#################################" >> ${LOGFILE}
echo ""
使用如下命令将 /etc/init.d/oracle 置为可执行文件:
chmod a+x /etc/init.d/oracle
至此,可使用如下命令对oracle进行启动和关闭
/etc/init.d/oracle start #启动oracle(包括数据库实例、监听器、EM)
/etc/init.d/oracle stop #关闭oracle
/etc/init.d/oracle restart #重启oracle
将 oracle 添加到 chkconfig中:
chkconfig --add oracle
可使用如下命令查看和设置oracle服务的开机启动级别:
chkconfig | grep oracle #查看oracle服务的开机启动级别
chkconfig --level 24 oracle off #修改oracle服务的开机启动级别
chkconfig --level 35 oracle on
至此可使用如下命令对oracle的启动或关闭进行管理
service oracle start #启动
service oracle stop #关闭
service oracle restart #重启
建立连接:
ln -s /etc/init.d/oracle /etc/rc0.d/K01oracle #关机执行
ln -s /etc/init.d/oracle /etc/rc6.d/K01oracle #重启执行
#!/bin/sh
#chkconfig: 2345 20 80
#description: Oracle dbstart / dbshut
#以上两行为chkconfig所需
ORA_HOME=/opt/oracle/11g
ORA_OWNER=oracle
LOGFILE=/var/log/oracle.log
echo "#################################" >> ${LOGFILE}
date +"### %T %a %D: Run Oracle" >> ${LOGFILE}
if [ ! -f ${ORA_HOME}/bin/dbstart ] || [ ! -f ${ORA_HOME}/bin/dbshut ]; then
echo "Error: Missing the script file ${ORA_HOME}/bin/dbstart or ${ORA_HOME}/bin/dbshut!" >> ${LOGFILE}
echo "#################################" >> ${LOGFILE}
exit
fi
start(){
echo "###Startup Database..."
su - ${ORA_OWNER} -c "${ORA_HOME}/bin/dbstart ${ORA_HOME}"
echo "###Done."
echo "###Run database control..."
su - ${ORA_OWNER} -c "${ORA_HOME}/bin/emctl start dbconsole"
echo "###Done."
}
stop(){
echo "###Stop database control..."
su - ${ORA_OWNER} -c "${ORA_HOME}/bin/emctl stop dbconsole"
echo "###Done."
echo "###Shutdown Database..."
su - ${ORA_OWNER} -c "${ORA_HOME}/bin/dbshut ${ORA_HOME}"
echo "###Done."
}
case "$1" in
'start')
start >> ${LOGFILE}
'stop')
stop >> ${LOGFILE}
'restart')
stop >> ${LOGFILE}
start >> ${LOGFILE}
esac
date +"### %T %a %D: Finished." >> ${LOGFILE}
echo "#################################" >> ${LOGFILE}
echo ""
使用如下命令将 /etc/init.d/oracle 置为可执行文件:
chmod a+x /etc/init.d/oracle
至此,可使用如下命令对oracle进行启动和关闭
/etc/init.d/oracle start #启动oracle(包括数据库实例、监听器、EM)
/etc/init.d/oracle stop #关闭oracle
/etc/init.d/oracle restart #重启oracle
将 oracle 添加到 chkconfig中:
chkconfig --add oracle
可使用如下命令查看和设置oracle服务的开机启动级别:
chkconfig | grep oracle #查看oracle服务的开机启动级别
chkconfig --level 24 oracle off #修改oracle服务的开机启动级别
chkconfig --level 35 oracle on
至此可使用如下命令对oracle的启动或关闭进行管理
service oracle start #启动
service oracle stop #关闭
service oracle restart #重启
建立连接:
ln -s /etc/init.d/oracle /etc/rc0.d/K01oracle #关机执行
ln -s /etc/init.d/oracle /etc/rc6.d/K01oracle #重启执行
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询