auto ash v1

startdate=$1
enddate=$2
#reporttype=$3
#reportformat='text'
oraclehome=`echo $ORACLE_HOME`


dbid=`sqlplus -s "/ as sysdba" <<EOF
set head off
set echo off
set feedback off
set linesize 120 ;
set pagesize 0;
set heading off;
select distinct dbid from gv\$database;
quit;
EOF
`

instname=`sqlplus -s "/ as sysdba" <<EOF
set head off
set echo off
set feedback off
set linesize 120 ;
set pagesize 0;
set heading off;
select instance_name from gv\$instance;
quit;
EOF
`
echo "generate the ash report sql...."
$ORACLE_HOME/bin/sqlplus -s "/ as sysdba" <<EOF

rem autoash.sql
set echo off;
set feedback off;
set termout on;
set heading off;
variable rpt_options number;
define NO_OPTIONS = 0;
-- define ENABLE_ADDM = 8;
rem according to your needs, the value can be 'text' or 'html'
define report_type='html';
column ext new_value ext noprint
column fn_name new_value fn_name noprint;
column lnsz new_value lnsz noprint;
select 'html' ext from dual where lower('&report_type') = 'html';
select 'ash_report_html' fn_name from dual where lower('&report_type') = 'html';
select '1500' lnsz from dual where lower('&report_type') = 'html';
set linesize &lnsz;
column report_name new_value report_name noprint;
select instance_name||'_ashrpt_1_'|| to_char(to_date('$startdate', 'yyyy-mm-dd hh24:mi:ss'), 'yyyymmddhh24miss') ||'.'||'&ext' report_name
from v$instance a;
set termout off;
spool &report_name;
select output from table(dbms_workload_repository.&fn_name('$dbid', '$inst_num',to_date('$startdate', 'yyyy-mm-dd hh24:mi:ss'),to_date('$enddate', 'yyyy-mm-dd hh24:mi:ss'),0));
spool off;
set termout on;
clear columns sql;
ttitle off;
repfooter off;
undefine report_name
undefine report_type
undefine fn_name
undefine lnsz
undefine NO_OPTIONS
quit;
EOF

chmod +x autoash.sh
sh autoash.sh '2016-06-29 10:15:00'  '2016-06-29 10:30:00'
原文地址:https://www.cnblogs.com/feiyun8616/p/6138004.html