Linux/unix Shell Monitoring Oracle Listener (monitor Listener)

Source: Internet
Author: User

Using shell scripts to monitor and manage Oracle databases will greatly simplify the workload of DBAs, such as common monitoring of instances, monitoring of monitors, monitoring of alarm logs, backup of databases, automatic mailing of AWR report, etc. This article gives the use of shell scripts to monitor Oracle listeners under Linux.

Reference for Linux Shell:
Linux/unix calling Sql,rman script in shell script
Linux/unix passing variables between shell SQL
Linux/unix Shell calls PL/SQL
Linux/unix Shell Monitoring Oracle Instance (monitor instance)

1. Monitoring Oracle Monitor Shell script

[Python]View PlainCopyprint?
  1. [Email protected]:~/dba_scripts/custom/bin> more ck_lsnr.sh
  2. # +-------------------------------------------------------+
  3. # + CHECK LISTENER STATUS and RESTART IT when FAILED |
  4. # + Author:robinson |
  5. # + blog:http://blog.csdn.net/robinson_0612 |
  6. # + Parameter:no |
  7. # +-------------------------------------------------------+
  8. #!/bin/bash
  9. # --------------------
  10. # Define Variable
  11. # --------------------
  12. If [-f ~/.bash_profile]; Then
  13. . ~/.bash_profile
  14. Fi
  15. timestamp= ' Date +%y%m%d%h%m '; Export TIMESTAMP
  16. dbalist="[email protected]"; Export dbalist
  17. Mailpath=/users/robin/dba_scripts/sendemail-v1. About
  18. Log_dir=/users/robin/dba_scripts/custom/log
  19. Log_file=${log_dir}/lsnr_status_$timestamp.log
  20. retention=2
  21. # -----------------------------------------
  22. # Define How many listeners need to monitor
  23. # -----------------------------------------
  24. db_count=6
  25. db[1]=cnbo1
  26. db[2]=cnbotst
  27. db[3]=cnmmbo
  28. db[4]=mmbotst
  29. db[5]=sybo2sz
  30. db[6]=cnbo2
  31. # -------------------------
  32. # Begin to check Listener
  33. # -------------------------
  34. Touch $LOG _file
  35. echo "' Date '" >> $LOG _file
  36. Echo "The following listeners is down on ' hostname '" >> $LOG _file
  37. echo "-----------------------------------------------" >> $LOG _file
  38. count=1
  39. While [$COUNT-le $DB _count];
  40. Do
  41. For DB in ${db[$COUNT]};
  42. Do
  43. Lsnr_flag= ' Ps-ef | Grep-i listener_${db[$COUNT]} | Grep-v grep '
  44. if [-Z ' $lsnr _flag]; Then
  45. echo "The Listener for the database ${db[$COUNT]} are down." >> $LOG _file
  46. echo "=======> Restart Listener for the database ${db[$COUNT]}" >> $LOG _file
  47. Lsnrctl start listener_${db[$COUNT]} >> $LOG _file
  48. Echo-e "------------------------------------------------------------------\ n" >> $LOG _file
  49. Fi
  50. Done
  51. Count= ' expr $COUNT + 1 '
  52. Done
  53. # --------------------------
  54. # Send Email
  55. # --------------------------
  56. Cnt= ' grep ' restart Listener "$LOG _file |wc-l '
  57. If [ "$cnt"-gt 0];then
  58. $MAILPATH/sendemail-f [email protected]2gotrade.com-t $DBALIST-u "Listener crashed on ' hostname '"-O Message-fi le= $LOG _file
  59. Else
  60. RM-RF $LOG _file
  61. Fi
  62. # ------------------------------------------------
  63. # Removing files older than $RETENTION parameter
  64. # ------------------------------------------------
  65. Find ${log_dir}-name "*lsnr_status*"-mtime + $RETENTION-exec rm {} \;
  66. Exit
  67. [Email protected]:/users/robin/dba_scripts/custom/bin>./ck_lsnr.sh
  68. Feb : szdb sendemail[18611]: Email was sent successfully!
  69. Fri Feb 1 : #下面是测试脚本邮件发送包含的内容
  70. The following listeners is down on szdb
  71. -----------------------------------------------
  72. The listener for the database CNBO1 are down .
  73. =======> Restart Listener for the database CNBO1
  74. Lsnrctl for linux:version 10.2. 0.3.0-production on 01-feb- : £º
  75. Copyright (c) 1991, 2006, Oracle.  All rights reserved.
  76. Starting/users/oracle/orahome10g/bin/tnslsnr:please wait ...
  77. Tnslsnr for linux:version 10.2. 0.3.0-production System parameter file is
  78. /users/oracle/orahome10g/network/admin/listener.ora
  79. Log messages Written To/users/oracle/orahome10g/network/log/listener_cnbo1.log
  80. Listening on: (Description= (Address= (protocol=tcp) (host=192.101. 7.2) (port=1901 )))
  81. Connecting to (Description= (address= (protocol=tcp) (host=192.101. 7.2) (port=1901 )))
  82. STATUS of the LISTENER
  83. ------------------------
  84. Alias Listener_cnbo1
  85. Version Tnslsnr for linux:version 10.2. 0.3.0-production
  86. Start Date 01-feb- : £º
  87. Uptime 0 days 0 hr. 0 min. 0 sec
  88. Trace level off
  89. Security on:local OS Authentication
  90. SNMP OFF
  91. Listener Parameter File/users/oracle/orahome10g/network/admin/listener.ora
  92. Listener Log File/users/oracle/orahome10g/network/log/listener_cnbo1.log
  93. Listening Endpoints Summary ...
  94. (Description= (address= (protocol=tcp) (host=192.101. 7.2) (port=1901 )))
  95. Services Summary ...
  96. Service "CNBO1" has 1 instance (s).
  97. Instance "CNBO1", status UNKNOWN, have 1 handler (s) for the This service ...
  98. The command completed successfully
  99. ------------------------------------------------------------------

2. Supplement
A, the above monitoring monitor script can monitor multiple listeners.
b, the name of the listener is defined in the format listener_$oracle_sid, the default listener is not considered, such as using the default listener to make the corresponding changes.
C, using an array of methods to define the instance name, each corresponding to a listener, to ensure that the Db_count value and the number of listeners to monitor the match.
D, each element of the array uses ORACLE_SID, and if it is a RAC, it can be changed to a host name.
E, if a listener outage is detected, the listener is automatically restarted and the message is sent.
F, use the SendEmail Mail Sender program to send mail. See: The Indispensable SendEmail
G. Deploy the script through crontab. In addition, Oracle 10g testing is available and Oracle 11g is being tested.

Ext.: http://blog.csdn.net/leshami/article/details/8563744

Linux/unix Shell Monitoring Oracle Listener (monitor listener)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.