Quantcast
Channel: Doyensys Allappsdba Blog..
Viewing all articles
Browse latest Browse all 1640

Script to generate AWR report for 7 days and send it as attachment in mail

$
0
0
$cat awr_7days2.sh

export ORACLE_HOME=/PROD/app/oracle/product/11.2.0/db_1
export PATH=$PATH:$ORACLE_HOME/bin
$ORACLE_HOME/bin/sqlplus -s '/as sysdba'<<EOF
@/home/oracle/gangai/awrrpt_script/7_days_24hr_AWR_report.sql


@/home/oracle/gangai/awrrpt_script/master_awr_control.sql
EOF
exit 0


$ cat awr_report_2.sh

for inst in PROD
do
export ORACLE_SID=$inst
export ORACLE_HOME=`grep $ORACLE_SID /home/oracle/gangai/oratab|awk -F : '{print $2}'`
export ORACLE_HOME=/PROD/app/oracle/product/11.2.0/db_1
export PATH=$PATH:$ORACLE_HOME/bin
export MAILEE="gangai.nathan@doyensys.com"
./awr_7days2.sh $inst
#mailx -s "AWR report in ${ORACLE_SID}/`hostname` Completed" $MAILEE < /home/oracle/gangai/awrrpt_script/${ORACLE_SID}_*.html
cd /home/oracle/gangai/awrrpt_script/
tar cvf html.tar *.html
mailx -s "AWR report in ${ORACLE_SID}/`hostname` Completed" -a html.tar $MAILEE < /dev/null
done



$ cat awrrpt_script/7_days_24hr_AWR_report.sql
set lines 300;
set serveroutput on
spool /home/oracle/gangai/awrrpt_script/master_awr_control.sql
select 'set head off' from dual;
declare
cursor c is
select d.dbid id,d.name name,min(s.snap_id) bs,max(s.snap_id) es from dba_hist_snapshot s,gv$database d where trunc(s.begin_interval_time) = trunc(sysdate) group by d.name,d.dbid
union
select d.dbid id,d.name name,min(s.snap_id) bs,max(s.snap_id) es from dba_hist_snapshot s,gv$database d where trunc(s.begin_interval_time) = trunc(sysdate-1) group by d.name,d.dbid
union
select d.dbid id,d.name name,min(s.snap_id) bs,max(s.snap_id) es from dba_hist_snapshot s,gv$database d where trunc(s.begin_interval_time) = trunc(sysdate-2) group by d.name,d.dbid
union
select d.dbid id,d.name name,min(s.snap_id) bs,max(s.snap_id) es from dba_hist_snapshot s,gv$database d where trunc(s.begin_interval_time) = trunc(sysdate-3) group by d.name,d.dbid
union
select d.dbid id,d.name name,min(s.snap_id) bs,max(s.snap_id) es from dba_hist_snapshot s,gv$database d where trunc(s.begin_interval_time) = trunc(sysdate-4) group by d.name,d.dbid
union
select d.dbid id,d.name name,min(s.snap_id) bs,max(s.snap_id) es from dba_hist_snapshot s,gv$database d where trunc(s.begin_interval_time) = trunc(sysdate-5) group by d.name,d.dbid
union
select d.dbid id,d.name name,min(s.snap_id) bs,max(s.snap_id) es from dba_hist_snapshot s,gv$database d where trunc(s.begin_interval_time) = trunc(sysdate-6) group by d.name,d.dbid
union
select d.dbid id,d.name name,min(s.snap_id) bs,max(s.snap_id) es from dba_hist_snapshot s,gv$database d where trunc(s.begin_interval_time) = trunc(sysdate-7) group by d.name,d.dbid;
begin
for c1 in c
loop
if c1.bs > 0 then
dbms_output.put_line('spool /home/oracle/gangai/awrrpt_script/'||c1.name||'_'
||c1.bs||'_'||c1.es||'.html');
dbms_output.put_line('select output from table(dbms_workload_repository.awr_report_html( '||c1.id||',1,'||
c1.bs||','||
c1.es||',0 ));');
dbms_output.put_line('spool off');
end if;
end loop;
end;
/
spool off;
set heading off
set pages 50000
set linesize 1500
set trimspool on
set trimout on
set term off
set verify off;
set feedback off;

Viewing all articles
Browse latest Browse all 1640

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>