Home Database Mysql Tutorial Linux/Unix shell 监控Oracle监听器(monitor listener)

Linux/Unix shell 监控Oracle监听器(monitor listener)

Jun 07, 2016 pm 05:26 PM
monitor

使用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待测。

linux

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Affordable Xiaomi Gaming Monitor G24i makes global debut with 180 Hz display and AMD FreeSync Affordable Xiaomi Gaming Monitor G24i makes global debut with 180 Hz display and AMD FreeSync Sep 11, 2024 am 06:39 AM

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

Alienware unveils unique 27” gaming monitor AW2725QF with dual resolution and refresh-rate modes Alienware unveils unique 27” gaming monitor AW2725QF with dual resolution and refresh-rate modes Aug 17, 2024 am 06:52 AM

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

IFA 2024 | Nitro GS272U M debuts as Acer\'s latest take on the smart gaming monitor IFA 2024 | Nitro GS272U M debuts as Acer\'s latest take on the smart gaming monitor Sep 05, 2024 am 06:41 AM

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

MSI: After user criticism, cheaper gaming OLEDs will also receive firmware updates - only after a potentially costly update MSI: After user criticism, cheaper gaming OLEDs will also receive firmware updates - only after a potentially costly update Jun 27, 2024 pm 10:03 PM

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

Deal | Samsung 32-inch 240 Hz 4K Odyssey Neo G8 gaming monitor gets massive 43% discount in Amazon deal Deal | Samsung 32-inch 240 Hz 4K Odyssey Neo G8 gaming monitor gets massive 43% discount in Amazon deal Aug 07, 2024 pm 08:52 PM

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

Deal | 34-inch Samsung Odyssey OLED G8 ultrawide gaming monitor drops to lowest price ever in 33% Amazon deal Deal | 34-inch Samsung Odyssey OLED G8 ultrawide gaming monitor drops to lowest price ever in 33% Amazon deal Aug 08, 2024 pm 01:13 PM

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

OLED with 480 Hz and QHD resolution: LG Display begins mass production of new gaming panels OLED with 480 Hz and QHD resolution: LG Display begins mass production of new gaming panels Sep 05, 2024 am 10:50 AM

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

Deal | Samsung gives away free Odyssey G3 gaming monitors with 44%-off Odyssey G9 and Ark OLED and mini-LED displays Deal | Samsung gives away free Odyssey G3 gaming monitors with 44%-off Odyssey G9 and Ark OLED and mini-LED displays Sep 13, 2024 pm 03:15 PM

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

See all articles