用shell脚本实现打印某一个小时的快照,如下:
#*************************************************************************
# FileName : get_awrrpt.sh
#*************************************************************************
# Author : wangwei
# CreateDate : 2014-08-25
# Description : this script create a snapshot of the specified
# time
#
#*************************************************************************
#!/bin/bash
export ORACLE_HOME=/oracle/oracle/app/oracle/product/11.2.0/dbhome_1
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:/sbin:/bin:/usr/sbin:/usr/bin
export ORACLE_SID=orcl_sid
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/lib32
export ORACLE_BASE=/oracle/oracle
#export ORA_NLS10=$ORACLE_HOME/nls/data
#export NLS_LANG="Simplified Chinese"_China.AL32UTF8
export NLS_LANG=American_America.AL32UTF8
export LANG=C
cd /home/oracle/awrrpt
v_time="$1"
sqlplus -s /nolog <<EOF
connect / as sysdba
set feedback off
set heading off
set termout off
set linesize 10000
set pagesize 50000
set trimspool on
set verify off
column dbid new_value dbid;
column inst_num new_value inst_num;
column bid new_value bid;
column eid new_value eid;
column file_name new_value file_name;
select * from (select a.dbid,
a.instance_number inst_num,
a.startup_time,
a.snap_id bid,
a.snap_id + 1 eid,
'awrrpt_'||a.instance_number ||'_' || to_number(to_char(a.end_interval_time, 'HH24')) || '_' ||
to_number(to_char(a.end_interval_time, 'HH24') + 1) ||'.html' file_name
from dba_hist_snapshot a
where to_char(a.end_interval_time,'YYYYMMDDHH24')=$v_time
order by bid
)
where inst_num = 1
/
spool &file_name
select output from table(dbms_workload_repository.awr_report_html(&dbid,&inst_num,&bid,&eid,8));
spool off
exit;
EOF
执行脚本./get_awrrpt.sh 2015010609 打印9点到10点的快照