首页 > 数据库 > mysql教程 > Linux/Unix shell 自动发送AWR report

Linux/Unix shell 自动发送AWR report

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
发布: 2016-06-07 16:46:46
原创
952 人浏览过

观察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

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板