自动生成awr报告并发送邮件

自动生成awr报告并发送邮件
第一种,不稳定

#!/bin/bash
export ORACLE_SID=$1
export ORACLE_BASE=/oracle/oracle
export ORACLE_HOME=/oracle/oracle/11.2.0.4
cd /home/oracle/awr_static
TIME=`date -d -3hour +"%H"` #12点跑,查9点-10点的AWR
AWR_FORMAT=html
NUM_DAYS=1
MIN_SNAP_ID=`$ORACLE_HOME/bin/sqlplus -S "/as sysdba" << EOF
set heading off trimspool on feedback off
SELECT trim(max(snap_id)) FROM DBA_HIST_SNAPSHOT where to_char(begin_interval_time,'hh24')=$TIME;
EOF`
MAX_SNAP_ID=0
MAX_SNAP_ID=`expr $MIN_SNAP_ID + 1`
AWR_LOG=/home/oracle/awr_static/AWR-$ORACLE_SID-`date '+%Y%m%d_%H'`.html

echo -e "$AWR_FORMAT\n$NUM_DAYS\n$MIN_SNAP_ID$MAX_SNAP_ID\n$AWR_LOG\n"|($ORACLE_HOME/bin/sqlplus -S "/as sysdba" @$ORACLE_HOME/rdbms/admin/awrrpt.sql) > /dev/null


TO_MAIL=xxx@xx.com
echo "awr static" |/usr/bin/mutt -s "$1 AWR static" $TO_MAIL -a $AWR_LOG -a $DB_HEALTHCHECK_FILE -R

rm *.html

0 12 * * 5 /bin/sh /home/oracle/awr_static/awr_static.sh prod1

第二种,建议选择这个

#!/bin/bash
export ORACLE_SID=$1
export ORACLE_BASE=/oracle/oracle
export ORACLE_HOME=/oracle/oracle/11.2.0.4
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
export LANG=en_US.UTF-8
cd /home/oracle/awr_static
TIME=`date -d -3hour +"%H"`
AWR_FORMAT=html
NUM_DAYS=1
MIN_SNAP_ID=`$ORACLE_HOME/bin/sqlplus -S "/as sysdba" << EOF
set heading off trimspool on feedback off
SELECT trim(max(snap_id)) FROM DBA_HIST_SNAPSHOT where to_char(begin_interval_time,'hh24')=$TIME;
EOF`
MAX_SNAP_ID=0
MAX_SNAP_ID=`expr $MIN_SNAP_ID + 1`
AWR_LOG=/home/oracle/awr_static/AWR-$ORACLE_SID-`date '+%Y%m%d_%H'`.html
DB_ID=`$ORACLE_HOME/bin/sqlplus -S "/as sysdba" << EOF
set heading off trimspool on feedback off
SELECT DBID FROM V\\\$DATABASE;
EOF`
INST_ID=`$ORACLE_HOME/bin/sqlplus -S "/as sysdba" << EOF
set heading off trimspool on feedback off
select instance_number from v\\\$instance;
EOF`

$ORACLE_HOME/bin/sqlplus -S "/as sysdba"<<!
set trimspool on feedback off termout off pagesize 0 heading off
spool $AWR_LOG
SELECT * FROM table(dbms_workload_repository.awr_report_html($DB_ID,$INST_ID,$MIN_SNAP_ID,$MAX_SNAP_ID));
spool off
exit;
!

TO_MAIL=fanboshi@uuzz.com,songqi@uuzz.com
echo "awr static" |/usr/bin/mutt -s "$1 AWR static" $TO_MAIL -a $AWR_LOG 

#rm $AWR_LOG
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值