怎么获取AWR的脚本
本篇内容介绍了“怎么获取AWR的脚本”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
#!/bin/bash#byraysuen#v02.~/.bash_profileAWR_FORMAT=htmlNUM_DAYS=2#############################################获取指定时间的snapid的函数############################################getsnapID(){BEGIN_SNAP_ID=`sqlplus-S/assysdba<<-RAYsetheadingofftrimspoolonfeedbackoffSELECTtrim(SNAP_ID)FROMDBA_HIST_SNAPSHOTa,v\\$instancebwhereto_char(END_INTERVAL_TIME,'yyyymmddhh34')='$1'anda.instance_number=b.instance_number;RAY`END_SNAP_ID=`sqlplus-S/assysdba<<-RAYsetheadingofftrimspoolonfeedbackoffSELECTtrim(SNAP_ID)FROMDBA_HIST_SNAPSHOTa,v\\$instancebwhereto_char(END_INTERVAL_TIME,'yyyymmddhh34')='$2'anda.instance_number=b.instance_number;RAY`#判断获取的snapid是否为空if[-z${BEGIN_SNAP_ID}];thenecho"Thescriptcannotgetavalidsnapid,pleaseenterarighttimefor-b."exit96fiif[-z${BEGIN_SNAP_ID}];thenecho"Thescriptcannotgetavalidsnapid,pleaseenterarighttimefor-e."exit96fiBEGIN_SNAP_ID=`echo${BEGIN_SNAP_ID}|sed's///g'`END_SNAP_ID=`echo${END_SNAP_ID}|sed's///g'`}#############################################获取帮助的函数############################################my_fun(){echo"SYNOPSIS:"echo"./GET_AWR.sh-bbegin_time-eend_time-nawr_name"echo"OPTIONS:"echo"-bspecifyatimeforbegintimeofawr,formatyyyymmddhh34"echo"-especifyatimeforbegintimeofawr,formatyyyymmddhh34"echo"-nspecifyanamefornameofawr"echo"EXAMPLE:"echo"./GET_AWR.SH-b2019051708-e2019051709-ntest"echo"./GET_AWR.sh-b\`date+'%Y%m%d18'-d'+1dayago'\`-e\`date+'%Y%m%d19'-d'+1dayago'\`-ntest"}#############################################脚本入口,获取参数############################################if[$#-lt1];thenecho"Youmustspecifyparameters:"echo"-bbegintimeofawr"echo"-eendtimeofawr"exit99fiwhile(($#>=1))doif["$1"=="-b"];thenshiftawrbegintime=$1shiftcontinuefiif["$1"=="-e"];thenshiftawrendtime=$1shiftcontinuefiif["$1"=="-n"];thenshiftawrname=$1shiftcontinuefiif["$1"=="-h"];thenmy_funexit0fishiftdone#############################################健壮性检查#############################################参数不可以为空if[-z${awrbegintime}];thenecho"Youmustspecifyparameters:-bforbegintimeofawr"exit98fiif[-z${awrendtime}];thenecho"Youmustspecifyparameters:-eforendtimeofawr"exit98fiif[-z${awrname}];thenecho"Youmustspecifyparameters:-nforreportnameofawr"exit98fi#判断参数为时间date-d"${awrbegintime:0:8}${awrbegintime:8:2}">/dev/null2>&1if[$?-ne0];thenecho"Thevalusof-bisinvaliddate."exit97fidate-d"${awrendtime:0:8}${awrendtime:8:2}">/dev/null2>&1if[$?-ne0];thenecho"Thevalusof-eisinvaliddate."exit97fi#############################################执行函数,获取snapid############################################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/assysdba@?/rdbms/admin/awrrpt.sql)>/dev/null#############################################帮助:#参数区分大小写#-bawr的开始时间,格式:yyyymmddhh34#-eawr的结束时间,格式:yyyymmddhh34#-nawr报告中的名字#例子:#./GET_AWR.SH-b"2019051708"-e"2019051709"-ntest#./GET_AWR.sh-b`date+'%Y%m%d18'-d'+1dayago'`-e`date+'%Y%m%d19'-d'+1dayago'`-ntest############################################
“怎么获取AWR的脚本”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。