每次启动关闭,都要敲一大串的命令,特别在学习或者测试环境,敲多了难免感觉烦,因而就写了个servcie脚本,利用的service命令简单的启动,关闭,重启Oracle数据库,同时开启或者关闭em和lsnrctl,下面附上shell脚本和测试结果
[root@jsb-ylw-5024 ~]# cat /etc/init.d/oracle
#!/bin/sh
#chkconfig: 35 85 15
#description:oracle
#function: start .. stop and restart the oracle instance on 11g R2 64bit
#author:lw.yang
#version: V.1.0
ORACLE_PID=`ps -ef |grep ora |grep -E 'smon|pmon|ckpt' |wc -l`
export ORACLE_BASE=/u01
export ORACLE_HOME=/u01/oracle
export ORACLE_SID=yang
export PATH=$ORACLE_HOME:/bin:$PATH
# Source function library.
. /etc/rc.d/init.d/functions
start() {
su - oracle<
lsnrctl start
sqlplus /nolog<
startup
exit
EOD
exit
EOF
}
stop() {
su - oracle<
lsnrctl stop
sqlplus /nolog<
shutdown immediate
exit
EOD
exit
EOF
}
case "$1" in
start)
start
touch /var/lock/subsys/oracle
;;
stop)
stop
;;
status)
if [ "$ORACLE_PID" = "3" ];then
echo "Oracle instance is running..."
else echo "Oracle instance is not running..."
fi
;;
restart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 1
esac
[root@jsb-ylw-5024 ~]# chmod +x /etc/init.d/oracle
[root@jsb-ylw-5024 ~]# chkconfig --add oracle
[root@jsb-ylw-5024 ~]# service oracle status
Oracle instance is not running...
[root@jsb-ylw-5024 ~]# service start
……………………………………输出省略………………………………………
SQL*Plus: Release 11.2.0.1.0 Production on Wed Sep 15 09:20:55 2010
Copyright (c) 1982, 2009, Oracle. All rights reserved.
SQL> Connected to an idle instance.
SQL> ORACLE instance started.
Total System Global Area 1620115456 bytes
Fixed Size 2213816 bytes
Variable Size 1040189512 bytes
Database Buffers 570425344 bytes
Redo Buffers 7286784 bytes
Database mounted.
Database opened.
SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[root@jsb-ylw-5024 ~]# service oracle status
Oracle instance is running...
[root@jsb-ylw-5024 ~]# service oracle stop
……………………………………输出省略………………………………………
SQL*Plus: Release 11.2.0.1.0 Production on Wed Sep 15 09:23:40 2010
Copyright (c) 1982, 2009, Oracle. All rights reserved.
SQL> Connected.
SQL> Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options