自動生成AWR報告並以郵件附件傳送

ljm0211發表於2012-07-02
#!/bin/ksh
# creator: 李連嘉
# function: get awr report
date
#設定環境變數
export ORACLE_SID=ywzkr
export ORACLE_HOME=/ywzkr_ora/product/10.2.0
export NLS_LANG=american_america.zhs16gbk

#設定執行是變數
SQLPLUS=$ORACLE_HOME/bin/sqlplus
LOGFILE=/ywzkr_ora/awr_report/logs/awrreport.txt     #日誌檔案
REPFILE=/ywzkr_ora/awr_report/worksh/awrreport.html     #報表檔案

#獲得最後2個快照點
$SQLPLUS -S system/passwd <set echo off
set feedback off
set heading off
set pagesize 0
set linesize 1000
set trimspool on
spool $LOGFILE
select snap_id from
(select snap_id from dba_hist_snapshot where instance_number=1
order by end_interval_time desc) where rownum<3;
spool off;
set echo on
set feedback on
set heading on
exit
EOF

line1=`tail -1 $LOGFILE`
line2=`head -l $LOGFILE`
echo "line1 is"$line1
echo "line2 is"$line2

#產生報表
rm $REPFILE
$SQLPLUS -S system/passwd <define begin_snap=$line1
define end_snap=$line2
define report_name=$REPFILE
define report_type=html
define num_days=1
@?/rdbms/admin/awrrpt
exit
EOF

#傳送郵件
cat $REPFILE | uuencode `date +%Y%m%d`'-'`hostname`awrreport.html | mailx -m -s `date +%Y%m%d`'-'`hostname`awrreport lilianjia@zking.com

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/11411056/viewspace-734302/,如需轉載,請註明出處,否則將追究法律責任。

相關文章