Linux/Unix shell 監控Oracle執行個體(monitor instance)

來源:互聯網
上載者:User

標籤:

  使用shell指令碼實現對Oracle資料庫的監控與管理將大大簡化DBA的工作負擔,如常見的對執行個體的監控,監聽的監控,警示日誌的監控,以及資料庫的備份,AWR report的自動郵件等。本文給出Linux 下使用 shell 指令碼來監控 Oracle 執行個體。

    Linux Shell的相關參考:
        Linux/Unix shell 指令碼中調用SQL,RMAN指令碼
        Linux/Unix shell sql 之間傳遞變數
        Linux/Unix shell 調用 PL/SQL

 

1、監控Oracle執行個體shell指令碼

[python] view plain copy  print?
  1. [email protected]:~/dba_scripts/custom/bin> more ck_inst.sh     
  2. # +-------------------------------------------------------+  
  3. # +    CHECK INSTANCE STATUS AND SEND MAIL                |  
  4. # +    Author : Robinson                                  |  
  5. # +    Blog   : http://blog.csdn.net/robinson_0612        |  
  6. # +    Desc:                                              |  
  7. # +         variable X_DB use to exclude some instance    |   
  8. # +-------------------------------------------------------+  
  9.   
  10. #!/bin/bash  
  11.   
  12. # --------------------------------------------  
  13. # Set environment vairable and define variable  
  14. # --------------------------------------------  
  15.   
  16. if [ -f ~/.bash_profile ]; then  
  17.     . ~/.bash_profile  
  18. fi  
  19.   
  20. ORATAB=/etc/oratab  
  21. TIMESTAMP=`date +%Y%m%d%H%M`      
  22. MAILPATH=/users/robin/dba_scripts/sendEmail-v1.56  
  23. LOG_DIR=/users/robin/dba_scripts/custom/log               
  24. LOG_FILE=${LOG_DIR}/ck_inst_$TIMESTAMP.log   
  25. DBALIST="[email protected];[email protected]"  
  26. X_DB=‘SYBO2SZ|CNQDII|CNFO‘  
  27. RETENTION=1  
  28.   
  29. # ----------------------  
  30. # Check instance status  
  31. # ----------------------  
  32.   
  33. if [ -z "$X_DB" ]; then  
  34.     X_DB=‘DUMMY‘  
  35. fi  
  36. {  
  37. echo "`date` "   
  38. echo "Oracle Database(s) Status on `hostname`"   
  39. echo "-----------------------------------------"   
  40. db=`egrep -i ":Y|:N" $ORATAB | cut -d":" -f1 | grep -v "\#" | grep -v "\*"`   
  41. pslist=`ps -ef | grep pmon | grep -v grep`  
  42. dblist=`for i in $db; do echo $i; done | grep -vP $X_DB`  
  43. for i in $dblist; do   
  44.     echo "$pslist" | grep "[oa]*_pmon_$i" > /dev/null 2>&1   
  45.     if (( $? )); then   
  46.         echo "Oracle Instance - $i: Down"   
  47.     else   
  48.         echo "Oracle Instance - $i: Up"   
  49.     fi  
  50. done;  
  51. }|tee -a ${LOG_FILE} 2>&1  
  52.   
  53. # ------------------------  
  54. # Send Email  
  55. # ------------------------  
  56.   
  57. cnt=`cat $LOG_FILE | grep Down | wc -l`  
  58. if [ "$cnt" -gt 0 ]; then  
  59.     $MAILPATH/sendEmail -f [email protected]2gotrade.com -t $DBALIST -u "Instance status on `hostname`" -o message-file=$LOG_FILE   
  60. fi  
  61.   
  62. # ------------------------------------------------  
  63. # Removing files older than $RETENTION parameter   
  64. # ------------------------------------------------  
  65.   
  66. find ${LOG_DIR} -name "ck_inst*.*" -mtime +$RETENTION -exec rm {} \;  
  67.   
  68. exit  
  69.   
  70. [email protected]:~/dba_scripts/custom/bin> ./ck_inst.sh   
  71. Fri Feb  1 15:10:41 CST 2013   
  72. Oracle Database(s) Status on SZDB  
  73. -----------------------------------------  
  74. Oracle Instance - CNBO1: Up  
  75. Oracle Instance - CNBOTST: Down  
  76. Oracle Instance - CNMMBO: Up  
  77. Oracle Instance - MMBOTST: Up  
  78. Oracle Instance - CNMMBOBK: Down  
  79. Oracle Instance - CI8960U: Up  
  80. Oracle Instance - CNBO2: Up  
  81. Feb 01 15:10:41 szdb sendEmail[16024]: Email was sent successfully!  

2、補充
  a、上面的指令碼根據/etc/oratab中列出的執行個體進行監控,可以監控多個執行個體。
  b、變數X_DB用於排除那些不需要監控的執行個體,如指令碼中排出了3個執行個體。也可以將該變數置空。
  c、如果X_DB的值為空白時,我們賦予了DUMMY,確保你的資料庫執行個體名沒有使用DUMMY,否則過濾不掉。
  d、監控指令碼在監控過程中只要有一個執行個體宕掉,則發送整個監控報告。
  d、使用了sendEmail郵件發送程式來發送郵件。參閱:不可或缺的 sendEmail
  e、尾部清除監控過程中產生的保留日期之前的日誌。

轉:http://blog.csdn.net/leshami/article/details/8563115

Linux/Unix shell 監控Oracle執行個體(monitor instance)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.