【SHELL】Linux系统 Oracle实例监控、重启 简易Shell脚本

Linux系统 Oracle实例监控、重启 简 易Shell脚本



实验环境
Red Hat Linux  Enterprise 5
Oracle Database 11g Enterprise  11.2.0.3.0 - 64bit

在Linux系统中,通过一个简单的shell脚本,监控Oracle实例。
添加到crontab计划任务,定时执行,可以再数据库实例异常关闭后及时启动实例。







点击(此处)折叠或打开

  1. #!/bin/bash

  2. echo \"################################################################\"
  3. echo \"##        Oracle Instance Monitor/Restart Shell               ##\"
  4. echo \"##                                                            ##\"
  5. echo \"## Created by: Lv Xinghao                                     ##\"
  6. echo \"## Email : lvxinghao@163.com                                  ##\"
  7. echo \"## Blog : http://blog.itpub.net/29475508/                     ##\"
  8. echo \"################################################################\"

  9. let i_num=\"`cat /etc/oratab | egrep \":Y|:N\" | awk -F \":\" \'{ print $1 }\' | wc -l`\"

  10. if [ $i_num -gt 0 ];then
  11. echo \"----------------------------------------------\"
  12. echo $i_num oracle instance installed in this system.
  13. echo \"----------------------------------------------\"
  14. cat /etc/oratab | egrep \":Y|:N\" | awk -F \":\" \'{ print $1 }\'
  15. cat /etc/oratab | egrep \":Y|:N\" | awk -F \":\" \'{ print $1 }\' > instance_name

  16. for i in `cat instance_name`
  17. do

  18. export ORACLE_SID=$i

  19. let smon_num=\"`ps -ef | grep $i | grep smon | grep -v grep |wc -l`\"

  20. if [ $smon_num -eq 1 ]; then

  21. echo \"------------------------------------------------\"
  22. echo Oracle instance $i is running
  23. echo \"------------------------------------------------\"
  24. sqlplus \'/as sysdba\' <<EOF
  25. select instance_name,status from v\\$instance;
  26. quit;
  27. EOF

  28. else
  29. echo \"------------------------------------------------\"
  30. echo start oracle instance $i :
  31. echo \"------------------------------------------------\"
  32. sqlplus \'/as sysdba\' <<EOF
  33. startup;
  34. select instance_name,status from v\\$instance;
  35. quit;
  36. EOF

  37. fi

  38. done

  39. else
  40. echo No oracle instance in this system or oracle instance not in /etc/
  41. fi
当Oracle实例未启动时 执行脚本

点击(此处)折叠或打开

  1. [oracle@beijing ~]$ sh /u03/shell/startinstance.sh
  2. ################################################################
  3. ## Oracle Instance Monitor/Restart Shell                      ##
  4. ##                                                            ##
  5. ## Created by: Lv Xinghao                                     ##
  6. ## Email : lvxinghao@163.com                                  ##
  7. ## Blog : http://blog.itpub.net/29475508/                     ##
  8. ################################################################
  9. ----------------------------------------------
  10. 2 oracle instance installed in this system.
  11. ----------------------------------------------
  12. BJ
  13. GZ
  14. ------------------------------------------------
  15. start oracle instance BJ :
  16. ------------------------------------------------

  17. SQL*Plus: Release 11.2.0.3.0 Production on Thu Jul 24 11:47:50 2014

  18. Copyright (c) 1982, 2011, Oracle. All rights reserved.

  19. Connected to an idle instance.

  20. idle>ORACLE instance started.

  21. Total System Global Area 626327552 bytes
  22. Fixed Size 2230952 bytes
  23. Variable Size 373294424 bytes
  24. Database Buffers 247463936 bytes
  25. Redo Buffers 3338240 bytes
  26. Database mounted.
  27. Database opened.
  28. idle>
  29. INSTANCE_NAME    STATUS
  30. ---------------- ------------
  31. BJ               OPEN

  32. idle>Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
  33. With the Partitioning, Oracle Label Security, OLAP, Data Mining,
  34. Oracle Database Vault and Real Application Testing options
  35. ------------------------------------------------
  36. start oracle instance GZ :
  37. ------------------------------------------------

  38. SQL*Plus: Release 11.2.0.3.0 Production on Thu Jul 24 11:47:57 2014

  39. Copyright (c) 1982, 2011, Oracle. All rights reserved.

  40. Connected to an idle instance.

  41. idle>ORACLE instance started.

  42. Total System Global Area 521936896 bytes
  43. Fixed Size 2229944 bytes
  44. Variable Size 322963784 bytes
  45. Database Buffers 192937984 bytes
  46. Redo Buffers 3805184 bytes
  47. Database mounted.
  48. Database opened.
  49. idle>
  50. INSTANCE_NAME STATUS
  51. ---------------- ------------
  52. GZ OPEN

  53. idle>Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
  54. With the Partitioning, Oracle Label Security, OLAP, Data Mining,
  55. Oracle Database Vault and Real Application Testing options
  56. [oracle@beijing ~]$





当Oracle实例已启动时 执行脚本

点击(此处)折叠或打开

  1. [oracle@beijing ~]$ sh /u03/shell/startinstance.sh
  2. ################################################################
  3. ## Oracle Instance Monitor/Restart Shell                      ##
  4. ##                                                            ##
  5. ## Created by: Lv Xinghao                                     ##
  6. ## Email : lvxinghao@163.com                                  ##
  7. ## Blog : http://blog.itpub.net/29475508/                     ##
  8. ################################################################
  9. ----------------------------------------------
  10. 2 oracle instance installed in this system.
  11. ----------------------------------------------
  12. BJ
  13. GZ
  14. ------------------------------------------------
  15. Oracle instance BJ is running
  16. ------------------------------------------------

  17. SQL*Plus: Release 11.2.0.3.0 Production on Thu Jul 24 11:40:36 2014

  18. Copyright (c) 1982, 2011, Oracle. All rights reserved.


  19. Connected to:
  20. Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
  21. With the Partitioning, Oracle Label Security, OLAP, Data Mining,
  22. Oracle Database Vault and Real Application Testing options

  23. sys@DGDB>
  24. INSTANCE_NAME    STATUS
  25. ---------------- ------------
  26. BJ               OPEN

  27. sys@DGDB>Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
  28. With the Partitioning, Oracle Label Security, OLAP, Data Mining,
  29. Oracle Database Vault and Real Application Testing options
  30. ------------------------------------------------
  31. Oracle instance GZ is running
  32. ------------------------------------------------

  33. SQL*Plus: Release 11.2.0.3.0 Production on Thu Jul 24 11:40:36 2014

  34. Copyright (c) 1982, 2011, Oracle. All rights reserved.


  35. Connected to:
  36. Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
  37. With the Partitioning, Oracle Label Security, OLAP, Data Mining,
  38. Oracle Database Vault and Real Application Testing options

  39. sys@TESTDB>
  40. INSTANCE_NAME    STATUS
  41. ---------------- ------------
  42. GZ               OPEN

  43. sys@TESTDB>Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
  44. With the Partitioning, Oracle Label Security, OLAP, Data Mining,
  45. Oracle Database Vault and Real Application Testing options
  46. [oracle@beijing ~]$



来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29475508/viewspace-1226511/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/29475508/viewspace-1226511/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值