Linux/Unix shell 监控Oracle监听器(monitor listener)
使用shell脚本实现对Oracle数据库的监控与管理将大大简化DBA的工作负担,如常见的对实例的监控,监听的监控,告警日至的监控,以
使用shell脚本实现对Oracle数据库的监控与管理将大大简化DBA的工作负担,如常见的对实例的监控,监听的监控,告警日至的监控,以及数据库的备份,AWR report的自动邮件等。本文给出Linux 下使用 shell 脚本来监控 Oracle 监听器。
Linux Shell的相关参考:
Linux/Unix shell 脚本中调用SQL,RMAN脚本
Linux/Unix shell sql 之间传递变量
Linux Unix shell 调用 PL/SQL
Linux/Unix shell 监控Oracle实例(monitor instance)
1、监控Oracle监听shell脚本
robin@SZDB:~/dba_scripts/custom/bin> more ck_lsnr.sh
# +-------------------------------------------------------+
# + CHECK LISTENER STATUS AND RESTART IT WHEN FAILED |
# + Author : Robinson |
# + Blog :,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="robinson.cheng@12306.com"; export DBALIST
MAILPATH=/users/robin/dba_scripts/sendEmail-v1.56
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 are 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]} is 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 szdb@2gotrade.com -t $DBALIST -u "Listener crashed on `hostname`" -o message-file=$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
oracle@SZDB:/users/robin/dba_scripts/custom/bin> ./ck_lsnr.sh
Feb 01 17:16:34 szdb sendEmail[18611]: Email was sent successfully!
Fri Feb 1 17:16:33 CST 2013 #下面是测试脚本邮件发送包含的内容
The following listeners are down on SZDB
-----------------------------------------------
The listener for the database CNBO1 is down.
=======> restart listener for the database CNBO1
LSNRCTL for Linux: Version 10.2.0.3.0 - Production on 01-FEB-2013 17:16:33
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-2013 17:16:33
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, has 1 handler(s) for this service...
The command completed successfully
------------------------------------------------------------------
2、补充
a、上面的监控监听脚本可以监控多个监听器。
b、监听器的名字的定义格式为LISTENER_$ORACLE_SID,未考虑缺省监听器的情形,,如使用缺省监听器请做相应更改。
b、使用了数组的方式来定义实例名,每一个对应一个监听器,确保DB_COUNT的值与需要监控的监听器个数相符。
c、数组的每一个元素使用的是ORACLE_SID,如果是RAC,可以将其改为主机名。
d、如果检测到监听器宕掉的情形则会自动重启监听并发送邮件。
e、使用了sendEmail邮件发送程序来发送邮件。参阅:不可或缺的 sendEmail
f、通过crontab来部署该脚本。另,Oracle 10g测试可用,Oracle 11g待测。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The Xiaomi Gaming Monitor G24i has made its global debut, and it's the most affordable option in the new lineup. It has an FHD IPS screen that the company claims is ideal for competitive gamers. The 23.8-inch panel has a 180 Hz refresh rate and 1 ms

Dell has just unveiled a new 27-inch IPS gaming monitor with a special and rather useful trick up its sleeve that should appeal to enthusiasts and professional gamers. With the press of a button, the Alienware AW2725QF can switch between two combinat

The NitroGS272U M has joined theAcer CS322Qin being introduced as a smart monitor atIFA 2024- however, theformer has the more gamer-like stand of itsGA-seriespredecessors. It also has a smaller 27-inch display - although the glare-free WQHD IPS panel

Monitors can now often be used with extensive setting options and come with their own firmware. A corresponding user interface can be updated as part of firmware updates, for example, and in principle new functions can also be implemented - or bugs c

Samsung's Odyssey gaming monitor line-up features some of the best gaming monitors money can buy, often delivering on top-tier features and specifications along with their flagship pricing. The Odyssey Neo G8 sits at the higher end of Samsung's Odyss

Samsung is currently running its Gaming Week sale event, discounting many of its top-notch gaming monitors from the Odyssey series. One such monitor, the Samsung Odyssey G85SB OLED (model LS34BG850SNXZA), is heavily discounted for the duration of the

LG Display recently announced in a press release that it had begun mass production of its latest OLED panel for gaming monitors. Specifically, this is a 27-inch OLED panel and the first of its kind to achieve a frame rate of 480 Hz, which is said to

Samsung's Odyssey G9 gaming monitor range offers some of the best — and most expensive— high-refresh OLED and mini-LED gaming monitors around. Fortunately, a current sale on Samsung's site has brought those exorbitant prices down by as much as 46%. T
