最近在学习shell编程,搞一点点小工具自动完成awr报告的收集工作,方便系统出现问题时问题排查。
脚本内容如下,系统收集每天开始时间6点结束时间20点的awr报告并存储在/u01/shell_t/awr/目录下
#! /bin/sh
export ORACLE_SID=PROD1
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
/u01/shell_t/awr/awrrpt_1_${name}_${date}.html
EOF
转载于:https://www.cnblogs.com/Clark-cloud-database/p/7813873.html