Linux/Unix shell monitoring Oracle instance (monitor instance)

Source: Internet
Author: User

Using shell scripts to monitor and manage Oracle databases will greatly simplify DBA workload, such as common instance monitoring, monitoring, and daily alert monitoring, and database backup, AWR report automatic mail, etc. This section describes how to use shell scripts to monitor Oracle instances in Linux.

Linux Shell:

Linux/Unix shell scripts call SQL and RMAN scripts

Passing variables between Linux/Unix shell SQL statements

Linux Unix shell calls PL/SQL

1. Monitor shell scripts for Oracle instances

Robin @ SZDB :~ /Dba_scripts/custom/bin> more ck_inst.sh
# + ------------------------------------------------------- +
# + Check instance status and send mail |
# + Author: Robinson |
# + Blog: http://blog.csdn, net/javasson_0612 |
# + Desc: |
# + Variable X_DB use to exclude some instance |
# + ------------------------------------------------------- +

#! /Bin/bash

#--------------------------------------------
# Set environment vairable and define variable
#--------------------------------------------

If [-f ~ /. Bash_profile]; then
.~ /. Bash_profile
Fi

ORATAB =/etc/oratab
TIMESTAMP = 'date + % Y % m % d % H % m'
MAILPATH =/users/robin/dba_scripts/sendEmail-v1.56
LOG_DIR =/users/robin/dba_scripts/custom/log
LOG_FILE =$ {LOG_DIR}/ck_inst _ $ TIMESTAMP. log
DBALIST = "robinson.cheng@12306.com; robinson_0612@12306.com"
X_DB = 'sybo2sz | CNQDII | cnfo'
RETENTION = 1

#----------------------
# Check instance status
#----------------------

If [-z "$ X_DB"]; then
X_DB = 'dummy'
Fi
{
Echo "'date '"
Echo "Oracle Database (s) Status on 'hostname '"
Echo "-----------------------------------------"
Db = 'egrep-I ": Y |: N" $ ORATAB | cut-d ": "-f1 | grep-v" \ # "| grep-v "\*"'
Pslist = 'ps-ef | grep pmon | grep-v grep'
Dblist = 'for I in $ db; do echo $ I; done | grep-vP $ X_DB'
For I in $ dblist; do
Echo "$ pslist" | grep "[oa] * _ pmon _ $ I">/dev/null 2> & 1
If ($? ); Then
Echo "Oracle Instance-$ I: Down"
Else
Echo "Oracle Instance-$ I: Up"
Fi
Done;
} | Tee-a $ {LOG_FILE} 2> & 1

#------------------------
# Send Email
#------------------------

Cnt = 'cat $ LOG_FILE | grep Down | wc-l'
If ["$ cnt"-gt 0]; then
$ MAILPATH/sendEmail-f szdb@2gotrade.com-t $ DBALIST-u "Instance status on 'hostname'"-o message-file = $ LOG_FILE
Fi

#------------------------------------------------
# Removing files older than $ RETENTION parameter
#------------------------------------------------

Find $ {LOG_DIR}-name "ck_inst *. *"-mtime + $ RETENTION-exec rm {}\;

Exit

Robin @ SZDB :~ /Dba_scripts/custom/bin>./ck_inst.sh
Fri Feb 1 15:10:41 CST 2013
Oracle Database (s) Status on SZDB
-----------------------------------------
Oracle Instance-CNBO1: Up
Oracle Instance-CNBOTST: Down
Oracle Instance-CNMMBO: Up
Oracle Instance-MMBOTST: Up
Oracle Instance-CNMMBOBK: Down
Oracle Instance-CI8960U: Up
Oracle Instance-CNBO2: Up
Feb 01 15:10:41 szdb sendEmail [16024]: Email was sent successfully!

2. Supplement

A. The preceding script Monitors multiple instances based on the instances listed in/etc/oratab.

B. The X_DB variable is used to exclude instances that do not need to be monitored. For example, three instances are excluded from the script. You can also leave this variable empty.

C. If the value of X_DB is null, we grant DUMMY to ensure that your database instance name does not use DUMMY; otherwise, the database cannot be filtered out.

D. The monitoring script sends the entire monitoring report as long as one instance goes down during the monitoring process.

D. Use the sendEmail mail program to send emails. For more information, see sendEmail.

E. Clear logs generated during the monitoring process before the retention date at the end.

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.