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?
- [Email protected]:~/dba_scripts/custom/bin> more ck_lsnr.sh
- # +-------------------------------------------------------+
- # + CHECK LISTENER STATUS and RESTART IT when FAILED |
- # + Author:robinson |
- # + blog:http://blog.csdn.net/robinson_0612 |
- # + Parameter:no |
- # +-------------------------------------------------------+
- #!/bin/bash
- # --------------------
- # Define Variable
- # --------------------
- If [-f ~/.bash_profile]; Then
- . ~/.bash_profile
- Fi
- timestamp= ' Date +%y%m%d%h%m '; Export TIMESTAMP
- dbalist="[email protected]"; Export dbalist
- Mailpath=/users/robin/dba_scripts/sendemail-v1. About
- Log_dir=/users/robin/dba_scripts/custom/log
- Log_file=${log_dir}/lsnr_status_$timestamp.log
- retention=2
- # -----------------------------------------
- # Define How many listeners need to monitor
- # -----------------------------------------
- db_count=6
- db[1]=cnbo1
- db[2]=cnbotst
- db[3]=cnmmbo
- db[4]=mmbotst
- db[5]=sybo2sz
- db[6]=cnbo2
- # -------------------------
- # Begin to check Listener
- # -------------------------
- Touch $LOG _file
- echo "' Date '" >> $LOG _file
- Echo "The following listeners is down on ' hostname '" >> $LOG _file
- echo "-----------------------------------------------" >> $LOG _file
- count=1
- While [$COUNT-le $DB _count];
- Do
- For DB in ${db[$COUNT]};
- Do
- Lsnr_flag= ' Ps-ef | Grep-i listener_${db[$COUNT]} | Grep-v grep '
- if [-Z ' $lsnr _flag]; Then
- echo "The Listener for the database ${db[$COUNT]} are down." >> $LOG _file
- echo "=======> Restart Listener for the database ${db[$COUNT]}" >> $LOG _file
- Lsnrctl start listener_${db[$COUNT]} >> $LOG _file
- Echo-e "------------------------------------------------------------------\ n" >> $LOG _file
- Fi
- Done
- Count= ' expr $COUNT + 1 '
- Done
- # --------------------------
- # Send Email
- # --------------------------
- Cnt= ' grep ' restart Listener "$LOG _file |wc-l '
- If [ "$cnt"-gt 0];then
- $MAILPATH/sendemail-f [email protected]2gotrade.com-t $DBALIST-u "Listener crashed on ' hostname '"-O Message-fi le= $LOG _file
- Else
- RM-RF $LOG _file
- Fi
- # ------------------------------------------------
- # Removing files older than $RETENTION parameter
- # ------------------------------------------------
- Find ${log_dir}-name "*lsnr_status*"-mtime + $RETENTION-exec rm {} \;
- Exit
- [Email protected]:/users/robin/dba_scripts/custom/bin>./ck_lsnr.sh
- Feb : szdb sendemail[18611]: Email was sent successfully!
- Fri Feb 1 : #下面是测试脚本邮件发送包含的内容
- The following listeners is down on szdb
- -----------------------------------------------
- The listener for the database CNBO1 are down .
- =======> Restart Listener for the database CNBO1
- Lsnrctl for linux:version 10.2. 0.3.0-production on 01-feb- : £º
- Copyright (c) 1991, 2006, Oracle. All rights reserved.
- Starting/users/oracle/orahome10g/bin/tnslsnr:please wait ...
- Tnslsnr for linux:version 10.2. 0.3.0-production System parameter file is
- /users/oracle/orahome10g/network/admin/listener.ora
- Log messages Written To/users/oracle/orahome10g/network/log/listener_cnbo1.log
- Listening on: (Description= (Address= (protocol=tcp) (host=192.101. 7.2) (port=1901 )))
- Connecting to (Description= (address= (protocol=tcp) (host=192.101. 7.2) (port=1901 )))
- STATUS of the LISTENER
- ------------------------
- Alias Listener_cnbo1
- Version Tnslsnr for linux:version 10.2. 0.3.0-production
- Start Date 01-feb- : £º
- Uptime 0 days 0 hr. 0 min. 0 sec
- Trace level off
- Security on:local OS Authentication
- SNMP OFF
- Listener Parameter File/users/oracle/orahome10g/network/admin/listener.ora
- Listener Log File/users/oracle/orahome10g/network/log/listener_cnbo1.log
- Listening Endpoints Summary ...
- (Description= (address= (protocol=tcp) (host=192.101. 7.2) (port=1901 )))
- Services Summary ...
- Service "CNBO1" has 1 instance (s).
- Instance "CNBO1", status UNKNOWN, have 1 handler (s) for the This service ...
- The command completed successfully
- ------------------------------------------------------------------
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)