#!/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