搜索
首页数据库mysql教程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待测。

linux

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
Affordable Xiaomi Gaming Monitor G24i makes global debut with 180 Hz display and AMD FreeSyncAffordable Xiaomi Gaming Monitor G24i makes global debut with 180 Hz display and AMD FreeSyncSep 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 modesAlienware unveils unique 27” gaming monitor AW2725QF with dual resolution and refresh-rate modesAug 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 monitorIFA 2024 | Nitro GS272U M debuts as Acer\'s latest take on the smart gaming monitorSep 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 updateMSI: After user criticism, cheaper gaming OLEDs will also receive firmware updates - only after a potentially costly updateJun 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 dealDeal | Samsung 32-inch 240 Hz 4K Odyssey Neo G8 gaming monitor gets massive 43% discount in Amazon dealAug 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

OLED with 480 Hz and QHD resolution: LG Display begins mass production of new gaming panelsOLED with 480 Hz and QHD resolution: LG Display begins mass production of new gaming panelsSep 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 | 34-inch Samsung Odyssey OLED G8 ultrawide gaming monitor drops to lowest price ever in 33% Amazon dealDeal | 34-inch Samsung Odyssey OLED G8 ultrawide gaming monitor drops to lowest price ever in 33% Amazon dealAug 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

Deal | Samsung gives away free Odyssey G3 gaming monitors with 44%-off Odyssey G9 and Ark OLED and mini-LED displaysDeal | Samsung gives away free Odyssey G3 gaming monitors with 44%-off Odyssey G9 and Ark OLED and mini-LED displaysSep 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

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
2 周前By尊渡假赌尊渡假赌尊渡假赌
仓库:如何复兴队友
4 周前By尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
4 周前By尊渡假赌尊渡假赌尊渡假赌

热工具

螳螂BT

螳螂BT

Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

mPDF

mPDF

mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中