很實用的Shell腳本(實踐版)_第1頁
很實用的Shell腳本(實踐版)_第2頁
很實用的Shell腳本(實踐版)_第3頁
很實用的Shell腳本(實踐版)_第4頁
很實用的Shell腳本(實踐版)_第5頁
已閱讀5頁,還剩11頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、ApacheLogRotate.sh echo 'date' ": Clean the apache logs"> /usr/WebSphere/IHS/logs/access_log> /usr/WebSphere/IHS/logs/error_log apforwinbk.shexport DayOfWeek='date +"%u"'cd /wasbackupcp -rf ./WASBackup_"$DayOfWeek".tar ./apbk archiveOld.shexport Ta

2、rgetDir=/erpHome/jln.ear/erp.war/$1 /$2export TT='date +"%Y%m%d"'export DayOfWeek='date +"%u"' if (test -e $TargetDir) thenmkdir -p /erpHome/shell/old/$1cd $TargetDir# zip -qm /erpHome/old/$1 /$2_$TT.zip 'find . -mtime +7| awk 'print $0 ''mv /erpHo

3、me/shell/old/$1 /$2_$DayOfWeek.zip /erpHome/shell/old/$1 /$2.zip.oldfind . -mtime +7| xargs nice -n 20 zip -qm/erpHome/shell/old/$1 /$2_$DayOfWeek.zip #find . -mtime +7FiarchiveOld2.sh. /erpHome/shell/setP.shexport DayOfWeek='date +"%u"'if test "$#" -lt 1 | test -z "

4、$1"thenecho At least one argument needed.exitfiif test ! -e "$ShellHome/old/$1"thencd $ShellHome/old/mkdir -p $1fiif test ! -e "$ERPHome/$1"thenecho "$ERPHome/$1" "does not exist"exitficd $ERPHome/$1mv $ShellHome/old/$1_$DayOfWeek.zip $ShellHome/old/$1.zi

5、p.oldfind . -mtime +7 -type f | xargs nice -n 20 zip -qm $ShellHome/old/$1_$DayOfWeek.zip#find . -mtime +7 -type farchiveOldAll.sh/erpHome/shell/archiveOld.sh work/dr/engine jrprint/erpHome/shell/archiveOld.sh work/de tmp/erpHome/shell/archiveOld2.sh public backupLog.shecho 'date' ": Ba

6、ckup the logs". /erpHome/shell/setP.shcd $ERPHome/waslogsmkdir old/mv std*_*.txt old/mv $LOGHome/LOG_$DD.zip $LOGHome/LOG.zip.oldzip -qmr $LOGHome/LOG_$DD.zip 'ls $ERPHome/waslogs | grep -Ev "std|FATAL_DEBUG.xml"'ls -l $LOGHome/LOG_$DD.zipecho 'date' ": Backup the

7、 logs done." backupWASAll.sh. /erpHome/shell/setP.shcd /erpHome#rename old backup fileecho "#" 'date' "ERP program backup #"#mv /wasbackup/WASBackup_"$DayOfWeek".tar /wasbackup/WASBackup_old.tar rm -Rf /wasbackup/erpbak/WASBackup_"$DayOfWeek".tar#

8、backup ERP programnice -n 20 tar -cf /wasbackup/erpbak/WASBackup_"$DayOfWeek".tar jln.ear/erp.war DIClientDIServer ThreadPool erpdatals -l /wasbackup/erpbak/WASBackup_"$DayOfWeek".tar collectAudit.sh. /erpHome/shell/setP.sh jlnaudit shutdownauditpr -v < /audit/trail | grep PRO

9、C_Execute > $LOGHome/AUDIT_$YYMMDD.txtmv /audit/trail $LOGHome/trail_$TTgzip $LOGHome/trail_$TTaudit startlast | grep "$TT2" > $LOGHome/LOGIN_$YYMMDD.txtgrep "$TT3" /var/adm/sulog > $LOGHome/SU_$YYMMDD.txt cplogs.shexport dd='perl -e 'y=localtime(timeO-86400); pr

10、intf "%02dn",$y3;'cd /erpHome/shell/logsmkdir /test/erplogscp ./LOG_"$dd".zip /test/erplogscpnmon.sh cd /worktmp/nmonexport dd='perl -e 'y=localtime(timeO-86400); printf "%02dn",$y3;' export d='date +%y%m'"$dd"export HOSTNAME='hostn

11、ame'export data="$HOSTNAME"_"$d"_"*" ftp -n <<EOF open 38 user nmon nmoncd $HOSTNAME put $data byeEOF ddd.shcd $1touch 11.txt filter.awkBEGIN DiscardURLs="/erp/de/deCommand /erp/jsp/" DiscardAmount=split(DiscardURLs,DiscardURL," ")

12、 ResponseThreshold=4.9999 nlines=0 totalCount=0function extractTime(myDate,aSize)if (aSize=2) return myDate2if (myDate2=" 上午 ") return myDate3split(myDate3,dates,":")return dates1+12 ":" dates2 ":" dates3function isSkip(myURL) for (i = 1; i <= DiscardAmount

13、; i+)if (index(myURL,DiscardURLi)>0) return 1return 0if (isSkip($3)=0) if (NF=10)totalCount+;if ($4 > ResponseThreshold)mySize=split($2,myDate," ")myTime=extractTime(myDate,mySize)print $1 "t" myTime "t" $3 "t" $4 "t" $5 "t" $6 nlines

14、+ ENDprint " 本日網(wǎng)頁執(zhí)行總次數(shù): " totalCount " (JSP,servlet ,但不包含圖片等靜態(tài)網(wǎng)頁,也不包含 /erp/jsp/ 開頭的這些監(jiān)控畫面)"print " 共 " nlines " 筆異常資料"formatHTML.awkBEGIN function getSysName(myURL) fCount=split(myURL,myArray,"/")return myArray3 function getMaxInArray(oArray,oResult,

15、oIndex)maxValue=0for (idx in oCount)if (oCountidx>maxValue)maxValue=oCountidxmaxSys=idxdelete oArraymaxSysoResultoIndex,1=maxSysoResultoIndex,2=maxValuefunction sort(array,result,thresHold)for(i=1;i<=5;i+)getMaxInArray(array,result,i)oSys=getSysName($3)if (NF!=6)print $0 "<br/>"

16、;elseoCountoSys+$2oRecord+;print "<tr style='background-color:#C4DAFF'><td>" $1 "</td><td>" "</td><td>" $3 "</td><td>" $4 "</td><td>" $5 "</td><td>" $6 "&l

17、t;/td></tr>" ENDoThreshold oRecord/10sort(oCount,oResult,oThreshold)print "</table>"print "<script>"max=oResult1,2for(i=1;i<=5;i+)print "addData("" (oResulti,2/max*100) "pt"," i ","" oResulti,1 ""

18、,""oResulti,2 "")"formatHTML.awk.oldBEGIN print "<html><head><meta http-equiv='Content-Type' content='text/html; charset=GBK'><style>td border:1px solid black;</style></head><body><H1 align> 執(zhí)行時間超 過 60 秒的網(wǎng)址

19、 </H1><table style='border:1px solid black' cellspacing=0 align=center>" if (NF!=6)print $0 "<br/>"else if (NR=1)print "<tr style='background-color:pink' align=center><td>" $1 "</td><td>" $2 "</td>

20、;<td>" $3 "</td><td>" $4 "</td><td>" $5 "</td><td>" $6 "</td></tr>" elseprint "<tr style='background-color:#C4DAFF'><td>" $1 "</td><td>"$2"</

21、td><td>" $3 "</td><td>" $4 "</td><td>" $5 "</td><td>" $6 "</td></tr>" ENDprint "</table></body></html>" htmlFoot.txt</script></body></html> htmlHead.txt

22、<html><head><meta http-equiv='Content-Type' content='text/html; charset=GBK'><style>import "/erp/html/dn/filtergrid.css".td2 border:0px.td3 border-right.div1 border:solid black 1px.div2 border:solid black 1px;text-align:right.div3 border:solid 1px wh

23、ite td border:1px solid black;</style><script language="javascript" type="text/javascript"src="/erp/html/dn/actb.js"></script><!-External script -><scriptlanguage="javascript"type="text/javascript"src="/erp/html/dn/tab

24、lefilter.js"></script><script language="javascript" type="text/javascript">function doFilter()var props = remember_grid_values: true, alternate_rows: true, rows_counter: true, rows_counter_text: "Displayed rows: ", btn_reset: true, btn_reset_text: &q

25、uot;Clear", btn_text: " > ", loader: true, loader_text: "Filtering data.", col_0: "select", col_1: "none", col_3: "none", col_4: "none", col_5: "select",display_all_text: "< Show all >", sort_select: true s

26、etFilterGrid("table1",props);</script><script>var Colors=new Array("green","red","blue","yellow","orange")function addData(oWidth,oIndex,oSys,oData)chartBlock.innerHTML+="<div class=div3 style='background-color:"

27、;+ Colors(oIndex%5) +"width="+ oWidth +"'></div>"sysBlock.innerHTML+="<div class='div1'>"+ oSys +"</div>"dataBlock.innerHTML+="<div class='div2'>"+ oData +"</div>"function doVisible()if (

28、vf1.innerText=" +")vf1.innerText=""chartBlock.style.visibility="visible"sysBlock.style.visibility="visible"dataBlock.style.visibility="visible"else vf1.innerText=" + "chartBlock.style.visibility="hidden"sysBlock.style.visibility=&

29、quot;hidden"dataBlock.style.visibility="hidden" </script></head><body><TABLE cellspacing=0 cellpadding=0><TR><TD width=100% class=td2><H1 align>執(zhí)行時間超過5秒的網(wǎng)址</H1></TD><div id=myChart style="border:black solid 1px"><

30、;TD class=td3 id=chartBlock style="visibility:hidden"></TD><TD class=td2 id=sysBlock style="visibility:hidden"></TD><TD class=td2 id=dataBlock style="visibility:hidden"><td id=vf1 UNSELECTABLE=on style="cursor:hand" onclick="

31、doVisible()"> + </td></div></TD></TR></TABLE><BUTTON UNSELECTABLE=on style="cursor:hand" onclick="doFilter()”>Filter</BUTTON><table id=table1 style='border:1px solid black' cellspacing=0 align=center><tr style='bac

32、kground-color:pink' align=center><td> 來 源電腦 </td><td> 時 間 </td><td> 網(wǎng) 址</td><td> 執(zhí)行時間 </td><td>QueryString</td><td>UserID </td></tr>increaseERPsh./erpHome/shell/setP.shcd /erpHomefind jln.ear -type f -mtime 2 -print

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

34、amp;1mv /erpHome/bx.ear/erp.war/access.txt /erpHome/shell/logs/access_$YYMMDD.txtawk -F "t" -f /erpHome/shell/filter.awk /erpHome/shell/logs/access_$YYMMDD.txt > /erpHome/shell/logs/temp.csv#echo "史方箓福,丁,呼 ,磅公 丁,QueryString,UserID" > /erpHome/shell/logs/temp2.csv echo ”來源電腦

35、,時間,網(wǎng)址,執(zhí)行時間,QueryString,UserID" > /erpHome/shell/logs/temp2.csv sort -t "," +3 -n -r /erpHome/shell/logs/temp.csv >> /erpHome/shell/logs/temp2.csvawk -F "," -f /erpHome/shell/formatHTML.awk /erpHome/shell/logs/temp2.csv > $ERPHome/public/$YYMMDD.htmlgzip -v /erpH

36、ome/shell/logs/access_$YYMMDD.txt >> $NightLog 2>&1sv#awk -f /erpHome/shell/filter.awk /erpHome/shell/logs/access_$YYMMDD.txt > $ERPHome/public/$YYMMDD.html#gzip -v /erpHome/shell/logs/access_$YYMMDD.txt >> $NightLog 2>&1 night.sh ./erpHome/shell/setP.sh #/usr/WebSphere/

37、AppServer/bin/stopServer.sh server1 >> $NightLog 2>&1$ShellHome/backupLog.sh >> $NightLog 2>&1$ShellHome/ApacheLogRotate.sh >> $NightLog 2>&1#$ShellHome/processFile.sh db_serv2 0000 >> $NightLog 2>&1#mv $ERPHome/access.txt /erpHome/shell/logs/acces

38、s_$YYMMDD.txtawk -F "t" -f /erpHome/shell/filter.awk /erpHome/shell/logs/access_$YYMMDD.txt > /erpHome/shell/logs/temp.csvsort +3 -n -r /erpHome/shell/logs/temp.csv > /erpHome/shell/logs/temp2.csvcat /erpHome/shell/htmlHead.txt > $ERPHome/public/$YYMMDD.htmlawk -F "t" -f

39、 /erpHome/shell/formatHTML.awk /erpHome/shell/logs/temp2.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>

40、;&1#/usr/WebSphere/AppServer/bin/startServer.sh server1 >> $NightLog 2>&1 night.sh.bak. /erpHome/shell/setP.sh#/usr/WebSphere/AppServer/bin/stopServer.sh server1 >> $NightLog 2>&1$ShellHome/backupLog.sh >> $NightLog 2>&1$ShellHome/ApacheLogRotate.sh >>

41、; $NightLog 2>&1#$ShellHome/processFile.sh db_serv2 0000 >> $NightLog 2>&1#mv $ERPHome/access.txt /erpHome/shell/logs/access_$YYMMDD.txt#awk -F "t" -f /erpHome/shell/filter.awk /erpHome/shell/logs/access_$YYMMDD.txt > /erpHome/shell/logs/temp.csv#sort +3 -n -r /erpHo

42、me/shell/logs/temp.csv > /erpHome/shell/logs/temp2.csv#cat /erpHome/shell/htmlHead.txt > $ERPHome/public/$YYMMDD.html#awk -F "t" -f /erpHome/shell/formatHTML.awk /erpHome/shell/logs/temp2.csv >> $ERPHome/public/$YYMMDD.html#cat /erpHome/shell/htmlFoot.txt >> $ERPHome/publ

43、ic/$YYMMDD.htmlgzip -v /erpHome/shell/logs/access_$YYMMDD.txt >> $NightLog 2>&1/erpHome/shell/archiveOldAll.sh >> $NightLog 2>&1#/usr/WebSphere/AppServer/bin/startServer.sh server1 >> $NightLog 2>&1 #Old鼻.public!IHS.old.zip'public.zip.old#public 5.zip$publi

44、c 7.zip*public 1.zip%public 2.zip&pu blic 4.zip(public 6.zip)shell test.zipwork"public 3.zipxjhp55013:/erpHome/shell# processFile.shexport YYMM='/usr/bin/date +"%y%m"' export YYMMexport YYMMDD='/usr/bin/date +"%y%m%d"' export YYMMDDmkdir -p /nmon/report/$

45、1 /$YYMM/$YYMMDD/ cd /nmonnice -n 20 ./nmon2rrd -f $1_"$YYMMDD"_$2.nmon -d /nmon/report/$1 /$YYMM/$YYMMDD -x gzip -9 /nmon/report/$1 /$YYMM/$YYMMDD/*rrd*gzip -9 $1_"$YYMMDD"_$2.nmon res.sh/erpHome/shell/stopServer.sh $1/erpHome/shell/startServer.sh $1 restartjvm.sh/usr/WebSphere/

46、AppServer/profiles/AppSrv01/usr/WebSphere/AppServer/profiles/AppSrv01#/usr/WebSphere/AppServer/profiles/AppSrv01#/usr/WebSphere/AppServer/profiles/AppSrv01 rmGClog.shcd /usr/WebSphere/AppServer/profiles/AppSrv01> native_stderr.logcd /usr/WebSphere/AppServer/profiles/AppSrv01> native_stderr.log

47、cd /usr/WebSphere/AppServer/profiles/AppSrv01> native_stderr.log/bin/stopServer.sh s1/bin/startServer.sh s1/bin/stopServer.sh s2/bin/startServer.sh s2/logs/s1/logs/s2/logs/t1/logs/t2cd /usr/WebSphere/AppServer/profiles/AppSrv01 rmwasbackup.shcd /wasbackupfind . -ctime +1 -exec rm ;server.lst serv

48、er1startServer.shexport ERPHome=/erpHome/jln.ear/erp.war if ! test -e $ERPHomethenecho "Warning! " $ERPHome " not exists. exitfiexport ShellHome=/erpHome/shellexport LOGHome=/erpHome/shell/logsexport WAS_HOME=/usr/WebSphere/AppServerexport Java_Home=$WAS_HOME/java/export TT='date

49、+"%Y%m%d%H%M%S"'export TT2='date +"%b %d"'export TT3='date +"%m/%d"'export YYMMDD='date +"%Y%m%d"'export DD='date +"%d"'export UpdateLog=$LOGHome/update_$YYMMDD.txtexport NightLog=$LOGHome/night_$YYMMDD.txtexport D

50、ayOfWeek='date +"%u"' startAllService.sh/usr/WebSphere/IHS/bin/apachectl start/erpHome/ThreadPool/bin/go.sh start/erpHome/DIServer/bin/go.sh start/usr/WebSphere/AppServer/bin/startServer.sh server1#! /usr/bin/kshif test "$#" -lt 1 | test -z "$1" thenecho Usage:

51、$0 ServerNameecho "Available ServerName: "awk 'print "ttt" $1' /erpHome/shell/server.lst exitfiIFSsave=$IFSwhile IFS='' read line doif test $1 = $line thenexport ValidArg=1 breakfidone < /erpHome/shell/server.lst IFS=$IFSsaveif test -z "$ValidArg"then

52、echo Invalid ServerName.echo "Available ServerName: "awk 'print "ttt" $1' /erpHome/shell/server.lst exitfiexport ServerName=$1echo "# start $1 'date' #”>>/erpHome/shell/logs/serverRestart.log/usr/WebSphere/AppServer/bin/startServer.sh $1stopServer.sh#!

53、/usr/bin/kshif test "$#" -lt 1 | test -z "$1" thenecho Usage: $0 ServerNameecho "Available ServerName: "awk 'print "ttt" $1' /erpHome/shell/server.lst exitfiIFSsave=$IFSwhile IFS='' read line doif test $1 = $line thenexport ValidArg=1 breakfido

54、ne < /erpHome/shell/server.lst IFS=$IFSsaveif test -z "$ValidArg"thenecho Invalid ServerName.echo "Available ServerName: "awk 'print "ttt" $1' /erpHome/shell/server.lst exitfiexport ServerName=$1echo "# stop $1 'date' #”>>/erpHome/shell/log

55、s/serverRestart.log/usr/WebSphere/AppServer/bin/stopServer.sh $1syncConfig.sh cp /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

56、/AppServer/profiles/AppSrv01 /config/cells/p55013Cell01 /applications/jln.ear/ deployments/jln/erp.war/WEB-INF/usr/WebSphere/AppServer/profiles/Dmgr01 /bin/GenPluginCfg.sh syncConfig.sh.bakcp /erpHome/jln.ear/erp.war/WEB-INF/web.xml/usr/WebSphere/AppServer/profiles/Dmgr01 /config/cells/p510Cell01 /a

57、pplications/jln.ear/dep loyments/jln/erp.war/WEB-INFcp /erpHome/jln.ear/erp.war/WEB-INF/web.xml/usr/WebSphere/AppServer/profiles/AppSrv01 /config/cells/p510Cell01 /applications/jln.ear/de ployments/jln/erp.war/WEB-INF/usr/WebSphere/AppServer/profiles/Dmgr01 /bin/GenPluginCfg.shupdateFTPSrc.sh. /erpH

58、ome/shell/setP.shecho 'date' > $ERPHome/work/da/log/update/last.logexport DAHome=/home/ftpuser/pubif ! test $(find $DAHome -type f | wc -l) -eq 0 then>>echo 'date' ": Update source" >> $UpdateLog 2>&1echo "# Update the source #" $UpdateLog 2>&1echo $ERPHome >> $UpdateLog 2>&1/usr/bin/cp -r $DAHome/

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論