【SHELL】Linux系統 Oracle例項監控、重啟 簡易Shell指令碼

海星星hktk發表於2014-07-24
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/,如需轉載,請註明出處,否則將追究法律責任。

相關文章