Oracle database start and stop monitoring shell scripts

Source: Internet
Author: User

Achieve the following goals

1, monitor the Oracle database monitoring and the status of the instance, if the monitoring or the instance hangs, then starts, and the Mail informs, the script attempts to start the corresponding service

2, if the service started successfully, then the mail notification just hung, and now has started successfully, if the startup failed, then the MailTips, just hung, and still can not start;

The script is not complicated, but it is more elementary, but it realizes the requirement and tests it in the test environment, but still lacks some dead state monitoring, which needs to be further enhanced:

[Oracle@sdk31~]$ Cat/home/oracle/scripts/check_db_lis.SH#!/bin/bash#set-x
#这里导入环境变量 to prevent crontab execution from executing some commands under OracleExport oracle_home=/oracle/product/10.2.0/Db_1export Nls_lang=american_america.Zhs16gbkexport oracle_base=/Oracleexport PATH=$ORACLE _home/bin:$PATHExport Oracle_sid=dbcc# This is the configuration of the MAILX after the operating system installation MAILX, this is the sending mailbox I requested#/etc/mail/rc#set smtp=smtp.126.com#set [email protected] #set [email protected] smtp-auth-password=xxxxxx Smtp-auth=login
#配置发件人和相关系统变量mail_receive="Xxxxxxxxxxx@qq. com" Time= ' Date +%y%m%d_%h:%M:%s`hostname="192.168.0.31" Time= ' Date +'%y-%m-%d%h:%m:%s'' Oratab=/etc/
#或者数据库实例名以及pmon进程和监听进程, you can check the number of processes to determine whether the service terminates the SID= ' Cat/etc/oratab |grep-V"^#"|grep-V"^$"|cut-f1-d":"' Pmon_pid= ' Ps-ef |greppmon|grep-Vgrep' Listener_num= ' Ps-ef |greplistener|grep-Vgrep| WC-l '
#定义一些邮件的标题, content and other information, more cumbersome, need to simplify Title_dbs="oracle_${hostname}_${time}_instance_down!! alert!!"Title_dbsok="oracle_${hostname}_${time}_instance_recoverok!!"Title_dbsno="oracle_${hostname}_${time}_instance_recoverfail!!"Title_lis="oracle_${hostname}_${time}_listener_down!! alert!!"Title_lisok="oracle_${hostname}_${time}_listener_recoverok!!"Title_lisno="oracle_${hostname}_${time}_listener_recoverfail!!"contents_db="Oracle Instance down!! Please check!! Script would try to startup--[[' Date ']]"Contents_dbok="Minutes before,oracle Instance down,but Now it works OK check!!--[[' Date ']"Contents_dbno="Minutes before,oracle Instance down,but Now it can ' t start remained!##! Please check!! --[[' Date ']]"Contents_lis="Oracle Listener down!! Please check!! Script would try to startup--[[' Date ']]"Contents_lisok="Minutes before,oracle Listener down,but Now it works OK check!! --[[' Date ']]"Contents_lisno="Minutes before,oracle Listener down,but Now it can ' t start remained!##! Please check!! --[[' Date ']]"#定义主要的日志文件, can be sent as an attachment to a message Alert_log="/oracle/admin/dbcc/bdump/alert_dbcc.log"Listener_log="/oracle/product/10.2.0/db_1/network/log/listener.log"
#监听监控函数listener_monit () {if[$listener _num=0]then Echo ${contents_lis}| Mailx-v-S"${title_lis}"${mail_receive} >/dev/null2>&1Echo"${time}|${hostip}|oracle|down:listener"Echo"Listener down! Now you'll start it ... .."lsnrctl Start>/dev/NULLSleep 2Echo"Listener had started ......"listener_num_2= ' Ps-ef |greplistener|grep-Vgrep| WC-l 'if[$listener _num_2=1] then echo ${contents_lisok}| Mailx-v-S"${title_lisok}"${mail_receive} >/dev/null2>&1 ElseEcho ${contents_lisno}| Mailx-v-S"${title_lisno}"${mail_receive} >/dev/null2>&1fi elif [$listener _num=1] then echo"${time}|${hostip}|oracle|running:listener"fi} #数据库实例监控函数instance_monit () { forDBName in$sid; DoEcho"$pmon _pid"|grep "Ora_pmon_$sid">/dev/null2>&1if(( $?) then echo"${time}|${hostip}|oracle|down: $dbname"Echo ${contents_db}| Mailx-v-A ${alert_log}-s"${title_dbs}"${mail_receive} >/dev/null2>&1Echo"Instance down! Now you'll start it ... .."Sqlplus/nolog<<EOFConnect/As SysdbastartupEOFSleep 5Echo"Instance had started ......"Db_number= ' Ps-ef |grep 'ORA_PMON_DBCC'|grep-Vgrep| WC-l 'if[$db _number-ne0] then echo ${contents_dbok}| Mailx-v-A ${alert_log}-s"${title_dbsok}"${mail_receive} >/dev/null2>&1 ElseEcho ${contents_dbno}| Mailx-v-A ${alert_log}-s"${title_dbsno}"${mail_receive} >/dev/null2>&1fiElseEcho"${time}|${hostip}|oracle|running: $dbname"Fidone}listener_monitecho"--------------------------------------------------------"Instance_monit

Crontab Timer Deployment:

*/5 * * * */bin/sh/home/oracle/scripts/check_db_lis.sh >>/home/oracle/logs/check_db_lis.log

Of course, the premise of e-mail is to install MAILX and other mail-sending programs, and ensure that the system can be connected to the external network system

For example, the instance and listener all stop, the script automatically detects and executes, and receives 4 messages with the following effects:

The instance is hung, and the notification:

Notification after instance recovery:

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.