Linux系统 Oracle实例监控、重启 简
易Shell脚本
实验环境
Red Hat Linux Enterprise 5
Oracle Database 11g Enterprise 11.2.0.3.0 - 64bit
在Linux系统中,通过一个简单的shell脚本,监控Oracle实例。
添加到crontab计划任务,定时执行,可以再数据库实例异常关闭后及时启动实例。
![](http://img.blog.itpub.net/blog/attachment/201407/24/29475508_1406217271OU64.jpg?x-oss-process=style/bb)
点击(此处)折叠或打开
- #!/bin/bash
-
- echo \"################################################################\"
- echo \"## Oracle Instance Monitor/Restart Shell ##\"
- echo \"## ##\"
- echo \"## Created by: Lv Xinghao ##\"
- echo \"## Email : lvxinghao@163.com ##\"
- echo \"## Blog : http://blog.itpub.net/29475508/ ##\"
- echo \"################################################################\"
-
- let i_num=\"`cat /etc/oratab | egrep \":Y|:N\" | awk -F \":\" \'{ print $1 }\' | wc -l`\"
-
- if [ $i_num -gt 0 ];then
- echo \"----------------------------------------------\"
- echo $i_num oracle instance installed in this system.
- echo \"----------------------------------------------\"
- cat /etc/oratab | egrep \":Y|:N\" | awk -F \":\" \'{ print $1 }\'
- cat /etc/oratab | egrep \":Y|:N\" | awk -F \":\" \'{ print $1 }\' > instance_name
-
- for i in `cat instance_name`
- do
-
- export ORACLE_SID=$i
-
- let smon_num=\"`ps -ef | grep $i | grep smon | grep -v grep |wc -l`\"
-
- if [ $smon_num -eq 1 ]; then
-
- echo \"------------------------------------------------\"
- echo Oracle instance $i is running
- echo \"------------------------------------------------\"
- sqlplus \'/as sysdba\' <<EOF
- select instance_name,status from v\\$instance;
- quit;
- EOF
-
- else
- echo \"------------------------------------------------\"
- echo start oracle instance $i :
- echo \"------------------------------------------------\"
- sqlplus \'/as sysdba\' <<EOF
- startup;
- select instance_name,status from v\\$instance;
- quit;
- EOF
-
- fi
-
- done
-
- else
- echo No oracle instance in this system or oracle instance not in /etc/
- fi
![](http://img.blog.itpub.net/blog/attachment/201407/24/29475508_14062175724kCT.jpg?x-oss-process=style/bb)
点击(此处)折叠或打开
- [oracle@beijing ~]$ sh /u03/shell/startinstance.sh
- ################################################################
- ## Oracle Instance Monitor/Restart Shell ##
- ## ##
- ## Created by: Lv Xinghao ##
- ## Email : lvxinghao@163.com ##
- ## Blog : http://blog.itpub.net/29475508/ ##
- ################################################################
- ----------------------------------------------
- 2 oracle instance installed in this system.
- ----------------------------------------------
- BJ
- GZ
- ------------------------------------------------
- start oracle instance BJ :
- ------------------------------------------------
-
- SQL*Plus: Release 11.2.0.3.0 Production on Thu Jul 24 11:47:50 2014
-
- Copyright (c) 1982, 2011, Oracle. All rights reserved.
-
- Connected to an idle instance.
-
- idle>ORACLE instance started.
-
- Total System Global Area 626327552 bytes
- Fixed Size 2230952 bytes
- Variable Size 373294424 bytes
- Database Buffers 247463936 bytes
- Redo Buffers 3338240 bytes
- Database mounted.
- Database opened.
- idle>
- INSTANCE_NAME STATUS
- ---------------- ------------
- BJ OPEN
-
- idle>Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
- With the Partitioning, Oracle Label Security, OLAP, Data Mining,
- Oracle Database Vault and Real Application Testing options
- ------------------------------------------------
- start oracle instance GZ :
- ------------------------------------------------
-
- SQL*Plus: Release 11.2.0.3.0 Production on Thu Jul 24 11:47:57 2014
-
- Copyright (c) 1982, 2011, Oracle. All rights reserved.
-
- Connected to an idle instance.
-
- idle>ORACLE instance started.
-
- Total System Global Area 521936896 bytes
- Fixed Size 2229944 bytes
- Variable Size 322963784 bytes
- Database Buffers 192937984 bytes
- Redo Buffers 3805184 bytes
- Database mounted.
- Database opened.
- idle>
- INSTANCE_NAME STATUS
- ---------------- ------------
- GZ OPEN
-
- idle>Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
- With the Partitioning, Oracle Label Security, OLAP, Data Mining,
- Oracle Database Vault and Real Application Testing options
- [oracle@beijing ~]$
当Oracle实例已启动时 执行脚本
![](http://img.blog.itpub.net/blog/attachment/201407/24/29475508_14062175399bla.jpg?x-oss-process=style/bb)
点击(此处)折叠或打开
- [oracle@beijing ~]$ sh /u03/shell/startinstance.sh
- ################################################################
- ## Oracle Instance Monitor/Restart Shell ##
- ## ##
- ## Created by: Lv Xinghao ##
- ## Email : lvxinghao@163.com ##
- ## Blog : http://blog.itpub.net/29475508/ ##
- ################################################################
- ----------------------------------------------
- 2 oracle instance installed in this system.
- ----------------------------------------------
- BJ
- GZ
- ------------------------------------------------
- Oracle instance BJ is running
- ------------------------------------------------
-
- SQL*Plus: Release 11.2.0.3.0 Production on Thu Jul 24 11:40:36 2014
-
- Copyright (c) 1982, 2011, Oracle. All rights reserved.
-
-
- Connected to:
- Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
- With the Partitioning, Oracle Label Security, OLAP, Data Mining,
- Oracle Database Vault and Real Application Testing options
-
- sys@DGDB>
- INSTANCE_NAME STATUS
- ---------------- ------------
- BJ OPEN
-
- sys@DGDB>Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
- With the Partitioning, Oracle Label Security, OLAP, Data Mining,
- Oracle Database Vault and Real Application Testing options
- ------------------------------------------------
- Oracle instance GZ is running
- ------------------------------------------------
-
- SQL*Plus: Release 11.2.0.3.0 Production on Thu Jul 24 11:40:36 2014
-
- Copyright (c) 1982, 2011, Oracle. All rights reserved.
-
-
- Connected to:
- Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
- With the Partitioning, Oracle Label Security, OLAP, Data Mining,
- Oracle Database Vault and Real Application Testing options
-
- sys@TESTDB>
- INSTANCE_NAME STATUS
- ---------------- ------------
- GZ OPEN
-
- sys@TESTDB>Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
- With the Partitioning, Oracle Label Security, OLAP, Data Mining,
- Oracle Database Vault and Real Application Testing options
- [oracle@beijing ~]$
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29475508/viewspace-1226511/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29475508/viewspace-1226511/