#!/bin/bash
# creator: shark
# function: get addm report
# http://blog.csdn.net/zengmuansha
date
#设置环境变量
export ORACLE_SID=shark1
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
export NLS_LANG=american_america.zhs16gbk
#设置运行是变量
SQLPLUS=$ORACLE_HOME/bin/sqlplus
LOGFILE=/home/oracle/dbscripts/logs/addmreport.txt #日志文件
REPFILE=/home/oracle/dbscripts/logs/addmreporxt.txt #报表文件
#获得昨天开始和结束的2个快照点
$SQLPLUS -S shark/3838<<EOF
set echo off
set feedback off
set heading off
set pagesize 0
set linesize 1000
set trimspool on
set timing off
spool $LOGFILE
select snap_id
from dba_hist_snapshot
where instance_number=1
and begin_interval_time >= trunc(sysdate-1)
and end_interval_time < trunc(sysdate)
order by end_interval_time asc;
spool off;
set echo on
set feedback on
set heading on
exit
EOF
line1=`head -n 1 $LOGFILE`
line2=`tail -n 1 $LOGFILE`
echo "line1 is"$line1
echo "line2 is"$line2
set echo off
set feedback off
#产生报表
rm $REPFILE
$SQLPLUS -S shark/235619 <<EOF
define begin_snap=$line1
define end_snap=$line2
define report_name=$REPFILE
@?/rdbms/admin/addmrpt
exit
EOF
#发送邮件
mail -s `date +%Y%m%d%H`'-'`hostname`_addmreport [email protected] < $REPFILE