Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2343172
  • 博文数量: 535
  • 博客积分: 8689
  • 博客等级: 中将
  • 技术积分: 7066
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-26 10:00
文章分类

全部博文(535)

文章存档

2024年(4)

2023年(4)

2022年(16)

2014年(90)

2013年(76)

2012年(125)

2011年(184)

2010年(37)

分类: Oracle

2014-06-13 15:37:52





Oracle 入门之service脚本管理启动,关闭,重启





每次启动关闭,都要敲一大串的命令,特别在学习或者测试环境,敲多了难免感觉烦,因而就写了个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< emctl start dbconsole
lsnrctl start
sqlplus /nolog< conn /as sysdba
startup
exit
EOD
exit
EOF
}

stop() {
su - oracle< emctl stop dbconsole
lsnrctl stop
sqlplus /nolog< conn /as sysdba
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...

linux



[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



阅读(1809) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~