ITPub博客

首页 > 数据库 > Oracle > Shell实现每日自动导出AWR报表

Shell实现每日自动导出AWR报表

原创 Oracle 作者:vage_fang 时间:2015-11-12 17:27:15 0 删除 编辑
用Shell实现每日自动导出AWR(需要结合crontab设置计划)

#! /bin/sh

export ORACLE_SID=dbtest
echo $ORACLE_SID
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
m=(`sqlplus -S "/ as sysdba" << EOF
set pagesize 0 feedback off verify off heading off echo off
select max(snap_id) from dba_hist_snapshot where begin_interval_time>to_date(to_char(sysdate,'YYYY-MM-DD')||' 06
','YYYY-MM-DD HH24') and end_interval_time<=to_date(to_char(sysdate,'YYYY-MM-DD')||' 20','YYYY-MM-DD HH24');
EOF`)

n=(`sqlplus -S "/ as sysdba" << EOF
set pagesize 0 feedback off verify off heading off echo off
select min(snap_id) from dba_hist_snapshot where begin_interval_time>to_date(to_char(sysdate,'YYYY-MM-DD')||' 06
','YYYY-MM-DD HH24') and end_interval_time<=to_date(to_char(sysdate,'YYYY-MM-DD')||' 20','YYYY-MM-DD HH24');
EOF`)

name=(`sqlplus -S "/ as sysdba" << EOF
set pagesize 0 feedback off verify off heading off echo off
select instance_name from v\\\$instance;
EOF`)

date=(`sqlplus -S "/ as sysdba" << EOF
set pagesize 0 feedback off verify off heading off echo off
select to_char(sysdate,'yyyymmddhh24') from dual;
EOF`)

sqlplus -S "/ as sysdba" <<eof
@/u01/app/oracle/product/11.2.0/dbhome_1/rdbms/admin/awrrpt.sql;
html
1
$n
$m
/home/oracle/awr/awrrpt_1_${name}_${date}.html
EOF

name=`ls -lht awrrpt*|cut -d " " -f 9|sed -n '1p;1q'`
ftp -n << !
open 192.168.13.4
user awr awr
binary
cd AWR
lcd /home/oracle/awr/
prompt
mput ${name}
close
bye
!

减轻DBA工作量
</eof<>

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

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

注册时间:2013-05-01

  • 博文量
    16
  • 访问量
    69264