您好,欢迎访问一九零五行业门户网

Linux/Unix shell 监控Oracle实例(monitor instance)

使用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
1、监控oracle实例shell脚本
  robin@szdb:~/dba_scripts/custom/bin> more ck_inst.sh 
  # +-------------------------------------------------------+
  # +    check instance status and send mail                |
  # +    author : robinson                                  |
  # +    blog  : ,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.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、补充
a、上面的脚本根据/etc/oratab中列出的实例进行监控,可以监控多个实例。
b、变量x_db用于排除那些不需要监控的实例,如脚本中排出了3个实例。也可以将该变量置空。
c、如果x_db的值为空时,我们赋予了dummy,确保你的数据库实例名没有使用dummy,否则过滤不掉。
d、监控脚本在监控过程中只要有一个实例宕掉,则发送整个监控报告。
d、使用了sendemail邮件发送程序来发送邮件。参阅:不可或缺的 sendemail 见
e、尾部清除监控过程中产生的保留日期之前的日志。
其它类似信息

推荐信息