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

ljm0211發表於2012-07-02
#!/bin/ksh
# creator: 李連嘉
# function: get addm 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_addm_report/logs/addmreport.txt     #日誌檔案
REPFILE=/ywzkr_ora/awr_addm_report/worksh/addmreport.txt     #報表檔案

#獲得最後2個快照點
$SQLPLUS -S system/zjljm123 <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/zjljm123 <define begin_snap=$line1
define end_snap=$line2
define report_name=$REPFILE
@?/rdbms/admin/addmrpt
exit
EOF

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

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

相關文章