您好,登錄后才能下訂單哦!
本篇內(nèi)容介紹了“怎么獲取AWR的腳本”的有關(guān)知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細閱讀,能夠?qū)W有所成!
#!/bin/bash #by raysuen #v02 . ~/.bash_profile AWR_FORMAT=html NUM_DAYS=2 ############################################ #獲取指定時間的snapid的函數(shù) ############################################ getsnapID(){ BEGIN_SNAP_ID=`sqlplus -S / as sysdba <<-RAY set heading off trimspool on feedback off SELECT trim(SNAP_ID) FROM DBA_HIST_SNAPSHOT a,v\\$instance b where to_char(END_INTERVAL_TIME,'yyyymmddhh34')='$1' and a.instance_number=b.instance_number; RAY` END_SNAP_ID=`sqlplus -S / as sysdba <<-RAY set heading off trimspool on feedback off SELECT trim(SNAP_ID) FROM DBA_HIST_SNAPSHOT a,v\\$instance b where to_char(END_INTERVAL_TIME,'yyyymmddhh34')='$2' and a.instance_number=b.instance_number; RAY` #判斷獲取的snapid是否為空 if [ -z ${BEGIN_SNAP_ID} ];then echo "The script can not get a valid snap id,please enter a right time for -b." exit 96 fi if [ -z ${BEGIN_SNAP_ID} ];then echo "The script can not get a valid snap id,please enter a right time for -e." exit 96 fi BEGIN_SNAP_ID=`echo ${BEGIN_SNAP_ID} | sed 's/ //g'` END_SNAP_ID=`echo ${END_SNAP_ID} | sed 's/ //g'` } ############################################ #獲取幫助的函數(shù) ############################################ my_fun(){ echo "SYNOPSIS:" echo " ./GET_AWR.sh -b begin_time -e end_time -n awr_name" echo "OPTIONS:" echo " -b specify a time for begin time of awr,format yyyymmddhh34" echo " -e specify a time for begin time of awr,format yyyymmddhh34" echo " -n specify a name for name of awr" echo "EXAMPLE:" echo " ./GET_AWR.SH -b 2019051708 -e 2019051709 -n test" echo " ./GET_AWR.sh -b \`date +'%Y%m%d18' -d '+1 day ago'\` -e \`date +'%Y%m%d19' -d '+1 day ago'\` -n test" } ############################################ #腳本入口,獲取參數(shù) ############################################ if [ $# -lt 1 ];then echo "You must specify parameters:" echo " -b begin time of awr" echo " -e end time of awr" exit 99 fi while (($#>=1)) do if [ "$1" == "-b" ];then shift awrbegintime=$1 shift continue fi if [ "$1" == "-e" ];then shift awrendtime=$1 shift continue fi if [ "$1" == "-n" ];then shift awrname=$1 shift continue fi if [ "$1" == "-h" ];then my_fun exit 0 fi shift done ############################################ #健壯性檢查 ############################################ #參數(shù)不可以為空 if [ -z ${awrbegintime} ];then echo "You must specify parameters:-b for begin time of awr" exit 98 fi if [ -z ${awrendtime} ];then echo "You must specify parameters:-e for end time of awr" exit 98 fi if [ -z ${awrname} ];then echo "You must specify parameters:-n for report name of awr" exit 98 fi #判斷參數(shù)為時間 date -d "${awrbegintime:0:8} ${awrbegintime:8:2}" > /dev/null 2>&1 if [ $? -ne 0 ];then echo "The valus of -b is invalid date." exit 97 fi date -d "${awrendtime:0:8} ${awrendtime:8:2}" > /dev/null 2>&1 if [ $? -ne 0 ];then echo "The valus of -e is invalid date." exit 97 fi ############################################ #執(zhí)行函數(shù),獲取snap id ############################################ getsnapID ${awrbegintime} ${awrendtime} ############################################ #定義awr報告的路徑 ############################################ AWR_LOG=/u02/logout/awr/AWR_${awrname}_${awrbegintime}_${awrendtime}.html ############################################ #獲取awr報告 ############################################ echo -e "$AWR_FORMAT\n$NUM_DAYS\n$BEGIN_SNAP_ID\n$END_SNAP_ID\n$AWR_LOG\n"|(sqlplus -S / as sysdba @?/rdbms/admin/awrrpt.sql) > /dev/null ############################################ #幫助: # 參數(shù)區(qū)分大小寫 # -b awr的開始時間,格式:yyyymmddhh34 # -e awr的結(jié)束時間,格式:yyyymmddhh34 # -n awr報告中的名字 #例子: # ./GET_AWR.SH -b "2019051708" -e "2019051709" -n test # ./GET_AWR.sh -b `date +'%Y%m%d18' -d '+1 day ago'` -e `date +'%Y%m%d19' -d '+1 day ago'` -n test ############################################
“怎么獲取AWR的腳本”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。