很实用的Shell脚本实践版_第1页
很实用的Shell脚本实践版_第2页
很实用的Shell脚本实践版_第3页
很实用的Shell脚本实践版_第4页
很实用的Shell脚本实践版_第5页
已阅读5页,还剩19页未读 继续免费阅读

付费下载

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、ApacheLogRotate.sh echo 'date、Clean the apache logs11> /usr/WebSphere/IHS/logs/accessJog> /usr/WebSphere/IHS/logs/errorJog apforwinbk.shexport DayOfWeek=%date +,%u,xcd /wasbackupcp -rf ./WASBackup" $ DayOfWeek".tar ./apbk archiveOld.shexport TargetDir=/e rpHome/jlnear/erpwar7$l/$

2、2export TT='date +H%Y%m%d,%export DayOfWeek=%date +,%u,x 讦(test -e $TargetDir) thenmkdir -p /erp Home/shell/old/$lcd $TargetDir# zip -qm /erpHome/old/$l/$2_$TT.zip 'find . -mtime +71 awk print $0 八mv /erpHome/shell/old/$l/$2_$DayOfWeek.zip /erpHome/shell/old/$l/$2.zip.old find- mtime +7| xar

3、gs nice20 zip -qm/erpHome/shell/old/$l/$2_$DayOfWeek.zip# find . -mtime +7archiveOld2.sh /erpHome/shell/setP.shexport DayOfWeek=%date +,%u,xif test -Itl | test -z H$rthenecho At least one argument neededexitfiif test! -e "$ShellHome/old/$l"thencd $ShellHome/old/mkdir-p $1fiiftest !-e ,$ERP

4、Home/$l"thenecho ,$ERPHome/$l,1 "does not exist"exitficd $ERPHome/$lmv $ShellHome/old/$l_$DayOfWeek.zip $ShellHome/old/$l.zip.oldfind -mtime +7 type f | xargs nice -n 20 zip -qm $ShellHome/old/$l_$DayOfWeek.zip #find mtime +7 type farchiveOldAll.sh /erpHome/shell/archiveOld.sh work/dr

5、/engine jrprint/erpHome/shell/archiveOld.sh work/de tmp/erpHome/shell/archiveOld2.sh public backupLog.sh echo 'date' M: Backup the logs11 /erpHome/shell/setP.shcd $ERPHome/waslogsmkdir old/mv std*_*.txt old/mv $LOGHome/LOG.$DDzip $LOGHome/LOG.zip.oldzip -qmr $LOGHome/LOG_$DD.zip 'Is $ERP

6、Home/waslogs | grep -Ev "std | FArAL_DEBUG.xml,xIs -I $LOGHom“LOG-$DDzipecho 'date' Backup the logs done.11 backupWASAll.sh /erpHome/shell/setP.shcd /erpHome#rename old backup fileecho "#" 'date、"ERP program backup #H#mv /wasbackup/WASBackup_l>$DayOfWeekll.tar /was

7、backup/WASBackup_old.tarrm -Rf/wasbackup/erpbak/WASBackupJ'SDayOfWeek.tar#backup ERP programnice -n 20 tar -cf/wasbackup/erpbak/WASBackupJ,$DayOfWeek,.tar jln.ear/erp.war DiClientDiServer Thread Pool erpdataIs -I /wasbackup/erpbak/WASBackup-,$DayOfWeek',.tar collectAudit.sh./erpHome/shell/se

8、tRsh jinaudit shutdownauditpr-v < /audit/trail | grep PROC_Execute > $LOGHome/AUDIT_$YYMMDD.txt mv /audit/trail $LOGHome/trail_$TTgzip $LO G H o me/t ra il_$TTaudit startlast | grep”$TT¥ > $LOGHome/LOGIN_$YYMMDD.txtgrep "$TT3” /var/adm/sulog>$LOGHome/SU3YYMMDD.txt cplogs.shexpo

9、rt dd='perl -e ,y=localtime(time()-86400); printf,%02dn,l/$y3;,% cd /erpHome/shell/logsmkdir /test/erplogscp ./LOGJ'Sdd".zip/test/erplogscpnmon.shcd /worktmp/nmonexport dd=%perl -e >y=localtime(time()-86400); printf ”02dy $丫3;八export d=、date +%y%m',$ddHexport HOSTNAME='hostna

10、me'export datah$HOSTNAME”J$cr-”iftp -n «EOFopen 38user nmon nmoncd $HOSTNAMEput $databyeEOF ddd.shcd $1touch ll.txt filter.awkBEGIN DiscardURLs'Verp/de/deCommand /er*p力sp/" DiscardAmount=split(DiscardURLs/DiscardURL/>,") ResponseThreshold=4.9999nlines=0totalCount=0

11、function extractTimefmyDateSizeHif (aSize=2) return myDate2if (myDate2=" J:午")return myDate3splitfmyDateates/1:11)return datesl+12 11 :H dates211dates3function isSkip(myllRL) for (i = 1; i <= DiscardAmount; i+)if (index(myURL/DiscardURLi)>0) return 1return 0if (isSkip($3)=0) if (NF=1

12、0)totalCount+;讦($4 > ResponseThreshold)mySize=split($2/myDate/11 H) myTime=extractTime(myDate/mySize) print $1 "Xt" myTime ,tu $3 "V $4 ,f, $5 MtH $6 nlines+ENDprint "本日网页执行总次数:"totalCount " (JSP,servlet,但不包含图片等静态网页, 也不包含/erp/jsp/开头的这些监控画面)“print ”共H nlines H笔异常资料“fo

13、rmatHTML.awkBEGIN function getSysName(myllRL) fCountsplitfmyURLjmyArray/1/11)return myArray3function getMaxInArrayfoArraoResulolndexXmaxValue=Ofor (idx in oCount)if (oCountidx>maxValue)maxValue=oCountidxmaxSys=idxdelete oArraymaxSysoResultolndex,l=maxSysoResultolndex,2=maxValuefunction sortfarray

14、esulthresHoldXfor(i=l;i<=5;i+)getMaxInArrayfarray/esultJ)oSys=getSysName($3)if (NF!=6)print $0 ll<br/>,1elseoCountoSys+oRecord+;print "<tr style=,background-color:#C4DAFF,><td>" $1 ,</td><td>" $2 ,</tdxtd>,1 $3 ,</td><td>" $4 ,&l

15、t;/td><td>" $5 ,</td><td>" $6 "v/tdx/tr11ENDoThreshold oRecord/10sort(oCount,oResult,oThreshold)print "</table>"print ”vscript>”max=oResult 2for(i=l;i<=5;i+)print dDatafV111 (oResulti,2/max«100) ”ptT i MA,,H oResulti,l TA'111oResulti

16、,2 ,,r, A<xpvy 9S Ap±<p<y SS .Aplxpvy 痕Apyy ms Aplxp<y zs .Aplxpvy TS Ap4xu.:l<ato?:.loo¥p§oM>peqlla_At;iy4UHdTsu亠仝<xp<y 9S .AFxpvyApaxp<ysAp4xp<y ms Ap_xp<y ZS =AVA<V=rds ap4va<1i4uoohu 恐<5M.EdHOo¥pcnoM>peqllal-At;4V= lcHdaso宀Awqy OS

17、1 H9HZN 二!亠 =仝¥5。2型冇 OHUUQeds=a。>pJ3q p.os xdDapoqlla_At;上qzxTHvwKs09 划 Efe3<ACw-e ?VAAPOqvApea-c、vAu-At;、>5p<2q 卫os xdTuapoqp 关o-AlsvAxmoHlos-lelp -E>X5.UCWCOOudAlAU¥uooll>nbaa4 主 50EVAWWVA-E v= lcHd)Nb38 po&MelwlH 右E 主、V AAPOqydws'v VQaood-UQ-cunwxApoq、xa-qe<

18、y 辛d占N3(<html><head><meta http-equiv='Content-Type, content='text/html; charset=GBK'><style>import,7erp/html/dn/filtergrid.cssn;.td2 border:Opx.td3 border-right.divl border:solid black lpx.div2 border:solid black lpx;text-align:right.div3 border:solid lpx whitetd

19、border:lpx solid black;</style><script language-'javascript" type=,text/javascript,1 src=,/erp/html/dn/actb.js,></script><! External script ><scriptlanguage="javascript>>type=" text/javascript"src=,/erp/html/dn/tablefilter.js,x/script><s

20、cript language-'javascript" type=,text/javascript"> function doFilter()var props = remembergridvalues: true, alternate_rows: true, rowscounter: true, rows_counter_text: "Displayed rows: "z btn_reset: true, btn reset text: "Clear", btn.text:11 >lf, loader: true

21、, loader_text: "Filtering data爲 col-O: "select", col_l: "none' col.3: "none' col.4: "none' col.5: "select", display_all_text: "< Show all >", sort_select: truesetFilterGridC'tablel'props);</script><script>var Col

22、ors=new ArraygreenTrecTblueTyellow"r orange”) function addData(oWidtholndex,oSys,oData)chartBlock.innerHTML+="<div class=div3stylebackground-color:11+Colors(olndex%5) +"width=,+ oWidth +,></div>"sysBocFinnerHTML+HAdiv dass«'dc,lv=+ osys+A、d<5 da-aBocFinner

23、HlrML+H.Adiv dass'Ld<,2v=+ ODa£ +=<9:vvj function dovEbirxif (vflinnerTextH" +=)宀 vflinnerText'L j chartBocksty-evisib=:tyH<sib-o=j sysBocksty-p<.sibi-ity>'<:sibs:j da 击 Bocksty-e<.sibi-iw'L<sibs:je_se vf 1 .inn e rText'L + = j chartBockst<evi

24、sibi-'LhQlden=j sysBockst<essibi-ityH.hQ:den=j dataBocksty-e<.sibi-hy"hidde3=j<scrip(vAheadvAbodyvTABLE cfl-spacingHO ce=padding=ovATRVAHO wiehhHloof c-assud2v仝一兰弓viMf耳回曲5曲玄同洼<£><TDVAdiv idHmychart styQHo=ordero-ack so-id 1PX-VAHO c-assH-d3 idHchartBock sty0N<:sibi

25、-芽<hidderfvAHOVAHO dass"td2QlHsysBock styQ«'<:sibi-ity-rQlde3=v<TDVAHO£LassHtd2 iduda-aBock st<eH<Ebi一 ity:holde3vd idHvfl UNSELECTABLEHOn styQ>«cllrsor-rancr ondick'Ldovisibo(=>+<tdvAdivvAHOV<3atablevBUTTON UNSmLECTABLEHOn styo叫 cursonhancr ond

26、ick'LSOF 亍巾O.VF 亍 erABUTTONV aboQlMtabol styQllborderMpx SO-Q1b-ack ce-spacingHO a-ignHcen-erxq st<eH-backgroundcoor-u3,k a-ignHcen-erxtdvcw<tdx_dv s*aVAiv3津 A-dx-dvSICAdxtdvQuerystringcndxtdvuser-D A>dx>rvincreaseERP.sh /erpHome/shell/setP.shcd /erpHomefind jin.ear type f -mtime 2 -

27、print >/tmp/filelist.txtfind erpdata -type f-mtime 2 -print »/tmp/filelist.txttar cvfL/wasbackup/WASBackup_,l$DayOfWeek>l.tar/tmp/filelist.txt night.old /erpHome/shell/setP.sh$ShellHome/backupLog.sh » $NightLog 2>&1$ShellHome/ApacheLogRotate.sh » $NightLog 2>&1mv /

28、erpHome/bx.ear/erp.war/access.txt /erpHome/shell/logs/access_$YYMMDD.txtawk -F "Xt" -f /erpHome/shell/filter.awk /erpHome/shell/logs/accessYYMMDD.txt > /erpHome/shell/logs/temp.csv#echo "虫方箓福,丁,呼'磅a 丁queryStringUserlD" > /erpHome/shell/logs/temp2.csv echo "来源电脑'

29、;时间/网址/执行时间,QueryString,UserlD11 > /erpHome/shell/logs/temp2.csv sort -t +3 -n r /erpHome/shell/logs/temp.csv » /erpHome/shell/logs/temp2.csv awk F-f /erpHome/shell/formatHTML.awk /erpHome/shell/logs/temp2.csv >$ERPHome/public/$YYMMDD.htmlgzip -v /erpHome/shell/logs/access_$YYMMDD.txt 

30、87; $NightLog 2>&1#awk -f /erp Home/shell/filter.awk /erpHome/shell/logs/access_$YYMMDD.txt $ERPHome/public/$YYMMDD.html#gzip -v /erpHome/shell/logs/accessYYMMDD.txt » $NightLog 2>&1 night.sh /erpHome/shell/setP.sh #/usr/WebSphere/AppServer/bin/stopServer.sh serverl » $NightL

31、og 2>&1 $ShellHome/backupLog.sh » $ Night Log 2>&1$ShellHome/ApacheLogRotate.sh » $NightLog 2>&1#$ShellHome/processFile.sh db_serv2 0000 » $NightLog 2>&1#mv $ERPHome/access.txt /erpHome/shell/logs/access_$YYMMDD.txtawk -F "V" -f /erpHome/shell/fil

32、ter.awk /erpHome/shell/logs/access_$YYMI/IDD.txt > /erpHome/shell/logs/temp.csvsort +3 n -r /erpHome/shell/logs/temp.csv > /erpHome/shell/logs/temp2.csvcat /erpHome/shell/htmlHeadtxt > $ERRHome/public/$YYMMDD.htmlawk -F "V" -f /erpHome/shell/formatHTML.awk /erp Home/shell/logs/tem

33、p2.csv » $ERPHome/public/$YYMMDD.htmlcat /erpHome/shell/htmlFoot.txt» $ERPHome/public/$YYMMDD.html#gzip -v /erpHome/shell/logs/access_$YYMMDD.txt » $NightLog 2>&1/erpHome/shell/archiveOldAll.sh » $NightLog 2>&1#/usr/WebSphere/AppServer/bin/startServer.sh serverl 

34、87; $ Night Log 2>&1 night.sh.bak /erpHome/shell/setP.sh#/usr/WebSphere/AppServer/bin/stopServer.sh serverl » $NightLog 2>&1$ShellHome/backupLog.sh » $NightLog 2>&1$ShellHome/ApacheLogRotate.sh » $NightLog 2>&1#$ShellHome/processFile.sh db_serv2 0000 »

35、 $NightLog 2>&1#mv $ERPHome/access.txt /erpHome/shell/logs/access_$YYMMDD.txt#awk -F "Xt" -f /erpHome/shell/filter.awk /erpHome/shell/logs/access_$YYMMDD.txt >/erpHome/shell/logs/temp.csv#sort +3 -n -r /erpHome/shell/logs/temp.csv > /erpHome/shell/logs/temp2.csv#cat /erpHonw/s

36、hell/htmlHeadtxt > $ERRHome/public/$YYMMDD.html#awk F "Xt" -f /er*pH ome/shell/formatHTML.awk /erpHome/shell/logs/temp2.csv »$ERPHome/public/$YYMMDD.html#cat /erpHome/shell/htmlFoot.txt » $ERPHome/public/$YYMMDD.htmlgzip -v /erpHome/shell/logs/accessYYMMDD.txt » $NightLog

37、 2>&1/erpHome/shell/archiveOldAll.sh » $NightLog 2>&1#/usr/WebSphere/AppServer/bin/startServer.sh serverl » $ Night Log 2>&1Old黑public!lHSoldzip'publiczip.old #public_5.zip$public_7zip*public_lzip%public_2zip&public_4zip(public_6zip)shell_test.zipwork"publ

38、ic_3zipxjhp550:13:/erpHome/shell # processFile.shexport YYMM=7usr/bin/dateexport YYMMexport YYMMDD=7usr/bin/dateexport YYMMDDmkdir -p /nmon/report/$l/$YYMM/$YYMMDD/cd /nmonnice -n 20 ./nmon2rrd -f $lJ,$YYMMDD$2.nmon -d /nmon/report/$l/$YYMM/$YYMMDD -x gzip -9 /nmon/report/$l/$YYMM/$YYMMDD/*rrd*gzip

39、-9 $lJ,$YYMMDD,_$2.nmon res.sh/erpHome/shell/stopServer.sh $1/erpHome/shell/startServer.sh $1 restartjvm.sh/usr/WebSphere/AppServer/profiles/AppSrvOl/bin/stopServer.sh si /usr/WebSphere/AppServer/profiles/AppSrvOl/bin/startServer.sh si #/usr/WebSphere/AppServer/profiles/AppSrv01/bin/stopServer.sh s2

40、 #/usr/WebSphere/AppServer/profiles/AppSrv01/bin/startServer.sh s2 rmGClog.shcd /usr/WebSphere/AppServer/profiles/AppSrvOl/logs/sl> native_stderr.logcd /usr/WebSphere/AppServer/profiles/AppSrv01/logs/s2> native_stderr.logcd /usr/WebSphere/AppServer/profiles/AppSrvOl/logs/tl> native_stderr.l

41、ogcd /usr/WebSphere/AppServer/profiles/AppSrv01/logs/t2 rmwasbackup.shcd /wasbackupfind -ctime +1 -exec rm ;server. 1st serverlsetP.sh export ERPHome=/erpHome/jln.ear/erp.war讦! test $ERPHomethenecho "Warning! " $ERPHome 11 not exists, exitfiexport ShellHome=/erpHome/shellexport LOGHome=/er

42、pHome/shell/logsexport WAS_HOME=/usr/WebSphere/AppServerexport Java_Home=$WAS_HOME/java/export TT='dateexport TT2='date +H%b %d,xexport TT3='date +,%m/%d,1'export YYMMDD='date +H%Y%m%d,%export DD二、date +,%dH'export UpdateLog=$LOGHome/update_$YYMMDD.txtexport NightLog=$LOGHome

43、/night_$YYMMDD.txt export DayOfWeek=%date +,%u11' startAllService.sh/usr/WebSphere/lHS/bin/apachectl start/erpHome/ThreadPool/bin/go.sh start/erpHome/DIServer/bin/go.sh start/usr/WebSphere/AppServer/bin/startServer.sh serverlstartServer.sh #! /usr/bin/ksh if test -Itl | test -z n$rthenecho Usage

44、: $0 ServerNameecho "Available ServerName:"awk 'print "ttt" $1' /erpHome/shell/server.lstexitfiIFSsave=$IFSwhile IFS=" read linedoif test $1 = $linethenexport ValidArg=lbreakfidone < /erpHome/shell/server.lstIFS=$IFSsaveif test -z 'ValidArg"thenecho Inval

45、id ServerNameecho "Available ServerName:"awk 'print "ttt" $1' /erpHome/shell/server.lstexitfiexport ServerName=$lecho"#start $1 'date' #"»/erpHome/shell/logs/serverRestart Jog/usr/WebSphere/AppServer/bin/startServer.sh $1stopServer.sh #! /usr/bin/ks

46、hif test -Itl 11 test -z ,$1Hthenecho Usage: $0 ServerNameecho "Available ServerName:"awk 'print "ttt" $1' /erpHome/shell/server.lst exitfiIFSsave=$IFSwhile IFS=" read linedoif test $1 = $linethenexport ValidArg=lbreakfidone < /erpHome/shell/server.lstIFS=$IFSsave

47、if test -z aa$ValidArga>thenecho Invalid ServerNameecho "Available ServerName:"awk 'print "ttt" $1' /erpHome/shell/server.lst exitfiexport ServerName=$lecho”#stop $1 'date' #"»/erpHome/shell/logs/serverRestartog/usr/WebSphere/AppServer/bin/stopServer.

48、sh $1syncConfig.shcp /erpHome/jln.ear/erp.war/WEB-INF/web.xml/usr/WebSphere/AppServer/profiles/Dmgr01/config/cells/p55013Cell01/applications/jln.ear/d eployments/jln/erp.war/WEB-INFcp /erpHome/jln.ear/erp.war/WEB-INF/web.xml/usr/WebSphere/AppServer/profiles/AppSrv01/config/cells/p55013Cell01/applica

49、tions/jln.ear/ deployments/jln/e rp.war/WEB-INF/usr/WebSphere/AppServer/profiles/DmgrOl/bin/GenPluginC.sh syncConfig.sh.bakcp /erpHome/jln.ear/erp.war/WEB-INF/web.xml/usr/WebSphere/AppServer/profiles/Dmgr01/config/cells/p510Cell01/applications/jln.ear/dep loyments/jln/erp.war/WEB-INFcp /erpHome/jln.

50、ear/erp.war/WEB-INF/web.xml/usr/WebSphere/AppServer/profiles/AppSrv01/config/cells/p510Cell01/applications/jln.ear/de ployments/jln/e rp.war/WEB-INF/usr/WebSphere/AppServer/profiles/DmgrOl/bin/GenPluginC.shupdateFTPSrc.sh# /erpHome/shell/setP.shecho 'date' > $ERPHome/work/da/log/update/la

51、st.logexport DAHome=/home/ftpuser/pubif ! test $(find $DAHome -type f | wc -I) -eq 0thenecho 'date、Update source" » $UpdateLog 2>&1echo ”# Update the source #" »$UpdateLog 2>&1echo $ERPHome » $UpdateLog 2>&1/usr/bin/cp -r $DAHome/* $ERPHome » $UpdateLog 2>&1# /usr/bin/cp -r $DAHome/* /erpHome/shell/src » $UpdateLog 2>&1# /usr/bin/rm -fre $DAHome/* 

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论