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

Linux/Unix shell 自动发送AWR report

观察oracle数据库性能,oracle自带的awr 功能为我们提供了一个近乎完美的解决方案,通过awr特性我们可以随时从数据库提取awr报告
观察oracle数据库性能,oracle自带的awr 功能为我们提供了一个近乎完美的解决方案,,通过awr特性我们可以随时从数据库提取awr报告。不过awrrpt.sql脚本执行时需要我们提供一些交互信息,因此可以将其整合到shell脚本中来实现自动产生指定时段的awr报告并发送给相关人员。本文即是描述linux shell脚本来实现此功能。
1、shell脚本
robin@szdb:~/dba_scripts/custom/awr> more autoawr.sh
#!/bin/bash
# --------------------------------------------------------------------------+
#                  check alert log file                                    |
#  filename: autoawr.sh                                                    |
#  desc:                                                                  |
#      the script use to generate awr report and send mail automatic.      |
#      the sql script autoawr.sql call by this shell script.              |                         
#      default, the whole day awr report will be gathered.                | 
#      deploy it to crontab at 23:30                                        |
#      if you want to change the snap interval,please change autoawr.sql  |
#          and crontab configuration                                        |
#  usage:                                                                  |
#      ./autoawr.sh $oracle_sid                                            | 
#                                                                          |
#  author : robinson                                                      |
#  blog  :                             |
# --------------------------------------------------------------------------+
#
# --------------------------
#  check sid
# --------------------------
if [ -z ${1} ];then
    echo usage:
    echo       `basename $0` oracle_sid
    exit 1
fi
# -------------------------------
#  set environment here
# ------------------------------
if [ -f ~/.bash_profile ]; then
    . ~/.bash_profile
fi
export oracle_sid=$1
export machine=`hostname`
export mail_dir=/users/robin/dba_scripts/sendemail-v1.56
export mail_list='robinson.cheng@12306.com'
export awr_cmd=/users/robin/dba_scripts/custom/awr
export awr_dir=/users/robin/dba_scripts/custom/awr/report
export mail_fm='oracle@szdb.com'
retention=31
# ----------------------------------------------
# check if the database is running, if not exit
# ----------------------------------------------
db_stat=`ps -ef | grep pmon_$oracle_sid | grep -v grep| cut -f3 -d_`
if [ -z $db_stat ]; then
    #date >/tmp/db_${oracle_sid}_stauts.log
    echo $oracle_sid is not available on ${machine} !!!  # >>/tmp/db_${oracle_sid}_stauts.log
    mail_sub= $oracle_sid is not available on ${machine} !!!
    mail_body= $oracle_sid is not available on ${machine} at `date` when try to generate awr.
    $mail_dir/sendemail -u $mail_sub -f $mail_fm -t $mail_list -m $mail_body
    exit 1
fi;
# ----------------------------------------------
# generate awr report
# ----------------------------------------------
$oracle_home/bin/sqlplus /nologconnect / as sysdba;
@${awr_cmd}/autoawr.sql;
exit;
eof
其它类似信息

推荐信息