ITPub博客

首页 > Linux操作系统 > Linux操作系统 > awr_script_example

awr_script_example

原创 Linux操作系统 作者:golden_zhou 时间:2011-04-13 10:16:56 0 删除 编辑

wmrac01<*+ASM1*/home/grid/dba/run>$cat awrrun
#!/bin/sh

cd  /u01/awrrpt

ORACLE_HOME=/u01/product/oracle/11.2.0/db_1;export ORACLE_HOME
ORACLE_SID=ccptdb1;export ORACLE_SID

$ORACLE_HOME/bin/sqlplus /nolog<connect / as sysdba;
@/u01/run/autoawr.sql;
exit
!

find  /u01/awrrpt/ccptdb*.html  -mmin  +4320 -exec rm -f {} \;


wmrac01<*+ASM1*/home/grid/dba/run>$cat autoawr.sql

rem autoawr.sql

set echo off;
set veri 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';
begin
  :rpt_options := &NO_OPTIONS;
end;
/

variable dbid number;
variable inst_num number;
variable bid number;
variable eid number;
begin
--select max(snap_id)-24 into :bid from dba_hist_snapshot;
  select min(snap_id) into :bid from dba_hist_snapshot where to_char(begin_interval_time,'yyyymmdd') = (select max(to_char(begin_interval_time,'yyyymmdd'))from dba_hist_snapshot) order by snap_id;
  select max(snap_id) into :eid from dba_hist_snapshot;
  select dbid into :dbid from v$database;
  select instance_number into :inst_num from v$instance;
end;
/

column ext new_value ext noprint
column fn_name new_value fn_name noprint;
column lnsz new_value lnsz noprint;

select 'txt' ext from dual where lower('&report_type') = 'text';
select 'html' ext from dual where lower('&report_type') = 'html';
select 'awr_report_text' fn_name from dual where lower('&report_type') = 'text';
select 'awr_report_html' fn_name from dual where lower('&report_type') = 'html';
select '80' lnsz from dual where lower('&report_type') = 'text';
select '1500' lnsz from dual where lower('&report_type') = 'html';

set linesize &lnsz;

column report_name new_value report_name noprint;

--select 'awrrpt_1'||:bid||'_'||:eid||'.'||'&ext' report_name from dual;
--select instance_name||'_awrrpt_'||instance_number||'_'||:bid||'_'||:eid||'.'||'&ext' report_name from v$instance;
select instance_name||'_awrrpt_'||instance_number||'_'||b.timestamp||'.'||'&ext' report_name from v$instance a ,(select to_char(begin_interval_time,'yyyymmdd') timestamp from dba_hist_snapshot where snap_id = :bid) b;
set termout off;
spool &report_name;

select output from table(dbms_workload_repository.&fn_name(:dbid, :inst_num,:bid,:eid,:rpt_options ));
spool off;
set termout on;
clear columns sql;
ttitle off;
btitle off;
repfooter off;
undefine report_name
undefine report_type
undefine fn_name
undefine lnsz
undefine NO_OPTIONS


wmrac01<*ccptdb1*/home/oracle>$crontab -l
30 0 * * * sh /u01/run/awrrun  1>/u01/run/log/autoawr.log  2>/u01/run/log/autoawr.bad

cat autoftp.bat
ftp -n -s:autoftp.txt 10.118.253.41
ftp -n -s:autoftp.txt 10.118.253.42

cat autoftp.txt
user
oracle
oracle#wmrac$
cd /u01/awrrpt/
lcd e:\ccptawr
bin
hash
prompt
mget *
bye

cat autosend.bat
ftp -n -s:d:\dba\autosend.txt 10.155.4.121
!

cat autosend.txt

user
dba
qazwsxedc123!
cd "CCPT AWR"
lcd e:\ccptawr
bin
hash
prompt
mput *.html
bye
!

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/25198367/viewspace-692384/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2011-03-09

  • 博文量
    238
  • 访问量
    308340