获取系统昨日最高峰时的AWR报告,get_hight_load_awr
运行get_hight_load_awr.sh,会自动收集昨日最高峰时刻的AWR报告,并上传到FTP服务器 . /home/oracle/.profile #get yestoday hight load time cat >/tmp/select.sql<<EOF spool /tmp/awrmax.txt set echo off feedback off underline off; . /home/oracle/.profile export ORACLE_SID=czloans cat >/tmp/select.sql<<EOF spool /tmp/awrmax.txt set echo off feedback off underline off; set linesize 1000 SELECT SUM(decode(to_char(first_time, 'hh24'),'00',1,0)) "0", SUM(decode(to_char(first_time, 'hh24'),'01',1,0)) "1", SUM(decode(to_char(first_time, 'hh24'),'02',1,0)) "2", SUM(decode(to_char(first_time, 'hh24'),'03',1,0)) "3", SUM(decode(to_char(first_time, 'hh24'),'04',1,0)) "4", SUM(decode(to_char(first_time, 'hh24'),'05',1,0)) "5", SUM(decode(to_char(first_time, 'hh24'),'06',1,0)) "6", SUM(decode(to_char(first_time, 'hh24'),'07',1,0)) "7", SUM(decode(to_char(first_time, 'hh24'),'08',1,0)) "8", SUM(decode(to_char(first_time, 'hh24'),'09',1,0)) "9", SUM(decode(to_char(first_time, 'hh24'),'10',1,0)) "10", SUM(decode(to_char(first_time, 'hh24'),'11',1,0)) "11", SUM(decode(to_char(first_time, 'hh24'),'12',1,0)) "12", SUM(decode(to_char(first_time, 'hh24'),'13',1,0)) "13", SUM(decode(to_char(first_time, 'hh24'),'14',1,0)) "14", SUM(decode(to_char(first_time, 'hh24'),'15',1,0)) "15", SUM(decode(to_char(first_time, 'hh24'),'16',1,0)) "16", SUM(decode(to_char(first_time, 'hh24'),'17',1,0)) "17", SUM(decode(to_char(first_time, 'hh24'),'18',1,0)) "18", SUM(decode(to_char(first_time, 'hh24'),'19',1,0)) "19", SUM(decode(to_char(first_time, 'hh24'),'20',1,0)) "20", SUM(decode(to_char(first_time, 'hh24'),'21',1,0)) "21", SUM(decode(to_char(first_time, 'hh24'),'22',1,0)) "22", SUM(decode(to_char(first_time, 'hh24'),'23',1,0)) "23" FROM v\$log_history where to_char(first_time,'yyyy-mm-dd')=to_char((sysdate-1),'yyyy-mm-dd') order by 1; spool off exit EOF sqlplus / as sysdba @/tmp/select.sql rm /tmp/select.sql htime=`awk 'NR==2{split($0,aa," ")}NR==3{maxidx=1;rst=$1;for(i=0;i<=NF;i++){if(rst<$i){rst=$i;maxidx=i;}};print aa[maxidx]}' /tmp/awrmax.txt` rm /tmp/awrmax.txt YESTODAY=`TZ=aaa24 date +%Y%m%d` YESTIME=$YESTODAY$htime echo $YESTIME #get hight load snapshot id m=`sqlplus -s /nolog <<EOF conn / as sysdba; set echo off feedback off heading off underline off; select snap_id from dba_hist_snapshot where to_char(begin_interval_time,'yyyymmddhh24')=\$YESTIME; exit; EOF` j=$((m-0)) k=$((m-1)) #get hight load awrrpt sqlplus / as sysdba <<EOF @$ORACLE_HOME/rdbms/admin/awrrpt.sql; html 1 ${k} ${j} /tmp/ftpfile/${ORACLE_SID}_awrrpt_1_${k}_${j}.html EOF #put awr to ftp MONTH=`TZ=aaa24 date +%Y%m` DAY=`TZ=aaa24 date +%d` ftp -i -n 10.1.24.217 <<! user admin 123456 bin prompt off cd /database/awr/$MONTH/$DAY lcd /tmp/ftpfile mput * bye !
坚持,专注