一個自動生成awr報告的shell指令碼

kisslfcr發表於2016-12-09
最近在學習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

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29135257/viewspace-2130163/,如需轉載,請註明出處,否則將追究法律責任。

相關文章