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

前端之家收集整理的这篇文章主要介绍了自动生成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
原文链接:https://www.f2er.com/oracle/208552.html

猜你在找的Oracle相关文章