定時自動生成awr報告
阿新 • • 發佈:2019-01-02
vi awr.sh
#!/bin/sh
ORACLE_SID=$1
export ORACLE_SID
source ~/.bash_profile
mkdir -p /oracle/utils/statspack/$1
WORKPATH=/oracle/utils/statspack/$1
AWR_FORMAT=html
NUM_DAYS=1
MAX_SNAP_ID=`sqlplus -S / as sysdba << EOF
set heading off trimspool on feedback off
SELECT trim(max(SNAP_ID)) FROM DBA_HIST_SNAPSHOT;
EOF`
export MAX_SNAP_ID
MIN_SNAP_ID=`expr $MAX_SNAP_ID - 1`
export MIN_SNAP_ID
echo $MIN_SNAP_ID
AWR_LOG=$WORKPATH/AWR_$1_${MIN_SNAP_ID}.html
export AWR_LOG
echo $AWR_LOG
echo -e "$AWR_FORMAT\n$NUM_DAYS\n$MIN_SNAP_ID$MAX_SNAP_ID\n$AWR_LOG\n"|(sqlplus -S / as sysdba @?/rdbms/admin/awrrpt.sql) > /dev/null
chmod +x awr.sh
./awr.sh orcl
注:orcl為資料庫的例項名
#!/bin/sh
ORACLE_SID=$1
export ORACLE_SID
source ~/.bash_profile
mkdir -p /oracle/utils/statspack/$1
WORKPATH=/oracle/utils/statspack/$1
AWR_FORMAT=html
NUM_DAYS=1
MAX_SNAP_ID=`sqlplus -S / as sysdba << EOF
set heading off trimspool on feedback off
SELECT trim(max(SNAP_ID)) FROM DBA_HIST_SNAPSHOT;
EOF`
export MAX_SNAP_ID
MIN_SNAP_ID=`expr $MAX_SNAP_ID - 1`
export MIN_SNAP_ID
echo $MIN_SNAP_ID
AWR_LOG=$WORKPATH/AWR_$1_${MIN_SNAP_ID}.html
export AWR_LOG
echo $AWR_LOG
echo -e "$AWR_FORMAT\n$NUM_DAYS\n$MIN_SNAP_ID$MAX_SNAP_ID\n$AWR_LOG\n"|(sqlplus -S / as sysdba @?/rdbms/admin/awrrpt.sql) > /dev/null
chmod +x awr.sh
./awr.sh orcl
注:orcl為資料庫的例項名