Using shell scripts to monitor and manage Oracle databases will greatly simplify the workload of DBAs, such as common monitoring of instances, monitoring of monitors, monitoring of alarm logs, backup of databases, automatic mailing of AWR report, etc. This article gives an example of using shell scripts to monitor Oracle instances under Linux.
Reference for Linux Shell:
Linux/unix calling Sql,rman script in shell script
Linux/unix passing variables between shell SQL
Linux/unix Shell calls PL/SQL
1. Monitoring Oracle Instance shell scripts
[Python]View PlainCopyprint?
- [Email protected]:~/dba_scripts/custom/bin> more ck_inst.sh
- # +-------------------------------------------------------+
- # + CHECK INSTANCE STATUS and SEND MAIL |
- # + Author:robinson |
- # + blog:http://blog.csdn.net/robinson_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. About
- Log_dir=/users/robin/dba_scripts/custom/log
- Log_file=${log_dir}/ck_inst_$timestamp.log
- dbalist="[Email protected];[ Email protected] "
- 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= ' fori in $db, do echo $i, done | GREP-VP $X _db '
- For i in $dblist;
- 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 [email protected]2gotrade.com-t $DBALIST-u "Instance status on ' hostname '"-O message-fil e= $LOG _file
- Fi
- # ------------------------------------------------
- # Removing files older than $RETENTION parameter
- # ------------------------------------------------
- Find ${log_dir}-name "ck_inst*.*"-mtime + $RETENTION-exec rm {} \;
- Exit
- [Email protected]:~/dba_scripts/custom/bin>./ck_inst.sh
- Fri Feb 1 :CST
- 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 : szdb sendemail[16024]: Email was sent successfully!
2. Supplement
A, the above script is monitored according to the instance listed in/etc/oratab, can monitor multiple instances.
b, the variable x_db is used to exclude instances that do not need to be monitored, such as 3 instances are discharged from a script. You can also leave the variable blank.
C, if the value of x_db is empty, we give dummy to ensure that your DB instance name is not used dummy, otherwise filtering will not be removed.
D, monitoring scripts in the monitoring process as long as one instance is down, the entire monitoring report is sent.
D. Use the SendEmail Mail Sender program to send mail. See: The Indispensable SendEmail
E, tail clear the log that precedes the retention date that is generated during the monitoring process.
Ext.: http://blog.csdn.net/leshami/article/details/8563115
Linux/unix Shell Monitoring Oracle Instance (monitor instance)