/usr/WebSphere/IHS/logs/access_log>/usr/WebSphere/IHS/logs/error_logapforwinbk.shexportDayOfWeek=`date+"%u"`cd/wasbackupcp-rf./WASBackup_"$DayOfWeek".tar./apbkarchiveOld.shexportTargetDir=/erpHome/jl" />
最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 正文

很实用的Shell脚本(实践版)

来源:动视网 责编:小OO 时间:2025-09-29 05:17:54
文档

很实用的Shell脚本(实践版)

ApacheLogRotate.shecho`date`":Cleantheapachelogs">/usr/WebSphere/IHS/logs/access_log>/usr/WebSphere/IHS/logs/error_logapforwinbk.shexportDayOfWeek=`date+"%u"`cd/wasbackupcp-rf./WASBackup_"$DayOfWeek".tar./apbkarchiveOld.shexportTargetDir=/erpHome/jl
推荐度:
导读ApacheLogRotate.shecho`date`":Cleantheapachelogs">/usr/WebSphere/IHS/logs/access_log>/usr/WebSphere/IHS/logs/error_logapforwinbk.shexportDayOfWeek=`date+"%u"`cd/wasbackupcp-rf./WASBackup_"$DayOfWeek".tar./apbkarchiveOld.shexportTargetDir=/erpHome/jl
ApacheLogRotate.sh

echo `date` ": Clean the apache logs"

> /usr/WebSphere/IHS/logs/access_log

> /usr/WebSphere/IHS/logs/error_log

apforwinbk.sh

export DayOfWeek=`date +"%u"`

cd /wasbackup

cp -rf  ./WASBackup_"$DayOfWeek".tar ./apbk

archiveOld.sh

export TargetDir=/erpHome/jln.ear/erp.war/$1/$2

export TT=`date +"%Y%m%d"`

export DayOfWeek=`date +"%u"`

if (test -e $TargetDir) then

        mkdir -p /erpHome/shell/old/$1

        cd $TargetDir

#       zip -qm /erpHome/old/$1/$2_$TT.zip `find . -mtime +7| awk '{print $0 }'`

        mv /erpHome/shell/old/$1/$2_$DayOfWeek.zip /erpHome/shell/old/$1/$2.zip.old

        find . -mtime +7 | xargs nice -n 20 zip -qm /erpHome/shell/old/$1/$2_$DayOfWeek.zip

#        find . -mtime +7

Fi

archiveOld2.sh  

. /erpHome/shell/setP.sh

export DayOfWeek=`date +"%u"`

if test "$#" -lt 1 || test -z "$1"

        then

                echo At least one argument needed.

                exit 

        fi

if test ! -e "$ShellHome/old/$1" 

then

        cd $ShellHome/old/

        mkdir -p $1

fi

if test ! -e "$ERPHome/$1" 

then

        echo "$ERPHome/$1" "does not exist"

        exit

fi

cd $ERPHome/$1

mv $ShellHome/old/$1_$DayOfWeek.zip $ShellHome/old/$1.zip.old

find . -mtime +7 -type f | xargs nice -n 20 zip -qm $ShellHome/old/$1_$DayOfWeek.zip

#find . -mtime +7 -type f

archiveOldAll.sh

/erpHome/shell/archiveOld.sh work/dr/engine jrprint

/erpHome/shell/archiveOld.sh work/de tmp

/erpHome/shell/archiveOld2.sh public

backupLog.sh

echo `date` ": Backup the logs"

. /erpHome/shell/setP.sh

cd $ERPHome/waslogs

mkdir old/

mv std*_*.txt old/

mv $LOGHome/LOG_$DD.zip $LOGHome/LOG.zip.old

zip -qmr $LOGHome/LOG_$DD.zip `ls $ERPHome/waslogs | grep -Ev "std|FATAL_DEBUG.xml"`

ls -l $LOGHome/LOG_$DD.zip

echo `date` ": Backup the logs done."

backupWASAll.sh

. /erpHome/shell/setP.sh

cd /erpHome 

#rename old backup file

echo "####" `date` "ERP program backup ####"

#mv /wasbackup/WASBackup_"$DayOfWeek".tar /wasbackup/WASBackup_old.tar

rm -Rf /wasbackup/erpbak/WASBackup_"$DayOfWeek".tar

#backup ERP program

nice -n 20 tar -cf /wasbackup/erpbak/WASBackup_"$DayOfWeek".tar jln.ear/erp.war DIClient DIServer ThreadPool erpdata

ls -l /wasbackup/erpbak/WASBackup_"$DayOfWeek".tar

collectAudit.sh

. /erpHome/shell/setP.sh jln

audit shutdown

auditpr -v < /audit/trail | grep PROC_Execute > $LOGHome/AUDIT_$YYMMDD.txt

mv /audit/trail $LOGHome/trail_$TT

gzip $LOGHome/trail_$TT

audit start

last | grep "$TT2" > $LOGHome/LOGIN_$YYMMDD.txt

grep "$TT3" /var/adm/sulog > $LOGHome/SU_$YYMMDD.txt

cplogs.sh

export dd=`perl -e '@y=localtime(time()-800); printf "%02d\\n",$y[3];'`

cd /erpHome/shell/logs

mkdir /test/erplogs 

cp ./LOG_"$dd".zip /test/erplogs

cpnmon.sh

cd /worktmp/nmon

export dd=`perl -e '@y=localtime(time()-800); printf "%02d\\n",$y[3];'`

export d=`date +%y%m`"$dd"

export HOSTNAME=`hostname`

export data="$HOSTNAME"_"$d"_"*"

ftp -n <open 10.32.1.138

user nmon nmon

cd $HOSTNAME

put $data

bye

EOF

ddd.sh

cd $1

touch 11.txt

filter.awk

BEGIN {

        DiscardURLs="/erp/de/deCommand /erp/jsp/"

        DiscardAmount=split(DiscardURLs,DiscardURL," ")

        ResponseThreshold=4.9999

        nlines=0

        totalCount=0

}

function extractTime(myDate,aSize){

        if (aSize==2) return myDate[2]

        if (myDate[2]=="上午") return myDate[3]

        split(myDate[3],dates,":")

        return dates[1]+12 ":" dates[2] ":" dates[3]

}

function isSkip(myURL) {

for (i = 1; i <= DiscardAmount; i++)

if (index(myURL,DiscardURL[i])>0) return 1

  return 0

}

{

        if (isSkip($3)==0) {

                if (NF==10){

                        totalCount++;

if ($4 > ResponseThreshold){

                                mySize=split($2,myDate," ")

                                myTime=extractTime(myDate,mySize)

                                print $1 "\" myTime "\" $3 "\" $4 "\" $5 "\" $6

                                nlines++

                        }

                }

        }

} END{

        print "本日网页执行总次数: " totalCount " (JSP,servlet,但不包含图片等静态网页,也不包含/erp/jsp/开头的这些监控画面)"

        print "共 " nlines " 笔异常资料"

formatHTML.awk

BEGIN {

}

function getSysName(myURL) {

        fCount=split(myURL,myArray,"/")

  return myArray[3]

}

function getMaxInArray(oArray,oResult,oIndex){

        maxValue=0

        for (idx in oCount){

if (oCount[idx]>maxValue){

                        maxValue=oCount[idx]

                        maxSys=idx

                }

        }

        delete oArray[maxSys]

        oResult[oIndex,1]=maxSys

        oResult[oIndex,2]=maxValue

}

function sort(array,result,thresHold){

for(i=1;i<=5;i++){

                getMaxInArray(array,result,i)

        }

}

{

        oSys=getSysName($3)

        if (NF!=6){

print $0 "
"

        }

        else{

                oCount[oSys]++

                oRecord++;

print "" $1 "" $2 "" $3 "" $4 "" $5 "" $6 ""

        }

} END{

        oThreshold oRecord/10

        sort(oCount,oResult,oThreshold)

print ""

print "

htmlHead.txt

执行时间超过 5 秒的网址

increaseERP.sh

. /erpHome/shell/setP.sh

cd /erpHome

find jln.ear -type f -mtime 2 -print >/tmp/filelist.txt

find erpdata -type f -mtime 2 -print >>/tmp/filelist.txt

tar 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>&1

mv /erpHome/bx.ear/erp.war/access.txt /erpHome/shell/logs/access_$YYMMDD.txt

awk -F "\" -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 "来源电脑,时间,网址,执行时间,QueryString,UserID" > /erpHome/shell/logs/temp2.csv

sort -t 

awk -F 

gzip -v /erpHome/shell/logs/access_$YYMMDD.txt >> $NightLog 2>&1

sv

#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/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/access_$YYMMDD.txt

awk -F "\" -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 /erpHome/shell/htmlHead.txt > $ERPHome/public/$YYMMDD.html

awk -F "\" -f /erpHome/shell/formatHTML.awk /erpHome/shell/logs/temp2.csv >> $ERPHome/public/$YYMMDD.html

cat /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 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 >> $NightLog 2>&1

#$ShellHome/processFile.sh db_serv2 0000 >> $NightLog 2>&1

#mv $ERPHome/access.txt /erpHome/shell/logs/access_$YYMMDD.txt

#awk -F "\" -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 /erpHome/shell/htmlHead.txt > $ERPHome/public/$YYMMDD.html

#awk -F "\" -f /erpHome/shell/formatHTML.awk /erpHome/shell/logs/temp2.csv >> $ERPHome/public/$YYMMDD.html

#cat /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 server1 >> $NightLog 2>&1

#

Old

 .馵..@public!IHS.old.zip'public.zip.old#public_5.zip$public_7.zip*public_1.zip%public_2.zip&public_4.zip(public_6.zip)shell_test.zipwork"public_3.zipxjh@p55013:/erpHome/shell#

processFile.sh

export YYMM=`/usr/bin/date +"%y%m"`; export YYMM

export YYMMDD=`/usr/bin/date +"%y%m%d"`; export YYMMDD

mkdir -p /nmon/report/$1/$YYMM/$YYMMDD/

cd /nmon

nice -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/AppServer/profiles/AppSrv01/bin/stopServer.sh s1

/usr/WebSphere/AppServer/profiles/AppSrv01/bin/startServer.sh s1

#/usr/WebSphere/AppServer/profiles/AppSrv01/bin/stopServer.sh s2

#/usr/WebSphere/AppServer/profiles/AppSrv01/bin/startServer.sh s2

rmGClog.sh

cd /usr/WebSphere/AppServer/profiles/AppSrv01/logs/s1

> native_stderr.log

cd /usr/WebSphere/AppServer/profiles/AppSrv01/logs/s2

> native_stderr.log

cd /usr/WebSphere/AppServer/profiles/AppSrv01/logs/t1

> native_stderr.log

cd /usr/WebSphere/AppServer/profiles/AppSrv01/logs/t2

rmwasbackup.sh

cd /wasbackup

find . -ctime +1 -exec rm {} \\;

server.lst

server1

setP.sh

export ERPHome=/erpHome/jln.ear/erp.war

if ! test -e $ERPHome

        then

                echo "Warning! " $ERPHome " not exists."

                exit

        fi

export ShellHome=/erpHome/shell

export LOGHome=/erpHome/shell/logs

export WAS_HOME=/usr/WebSphere/AppServer

export Java_Home=$WAS_HOME/java/

export TT=`date +"%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.txt

export NightLog=$LOGHome/night_$YYMMDD.txt

export DayOfWeek=`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

startServer.sh

#! /usr/bin/ksh

if test "$#" -lt 1 || test -z "$1"

        then

                echo Usage: $0 [ServerName]

                echo "Available ServerName: "

                awk '{print "\\\" $1}' /erpHome/shell/server.lst 

                exit 

        fi

IFSsave=$IFS

while IFS=''; read line

do

        if test $1 = $line

                then

                        export ValidArg=1

                        break

                fi

done < /erpHome/shell/server.lst

IFS=$IFSsave

if test  -z "$ValidArg"

        then

                echo Invalid ServerName.

                echo "Available ServerName: "

                awk '{print "\\\" $1}' /erpHome/shell/server.lst

                exit

        fi

export ServerName=$1

echo "#################### start $1 `date` ####################" >> /erpHome/shell/logs/serverRestart.log

/usr/WebSphere/AppServer/bin/startServer.sh $1

stopServer.sh

#! /usr/bin/ksh

if test "$#" -lt 1 || test -z "$1"

        then

                echo Usage: $0 [ServerName]

                echo "Available ServerName: "

                awk '{print "\\\" $1}' /erpHome/shell/server.lst 

                exit 

        fi

IFSsave=$IFS

while IFS=''; read line

do

        if test $1 = $line

                then

                        export ValidArg=1

                        break

                fi

done < /erpHome/shell/server.lst

IFS=$IFSsave

if test  -z "$ValidArg"

        then

                echo Invalid ServerName.

                echo "Available ServerName: "

                awk '{print "\\\" $1}' /erpHome/shell/server.lst

                exit

        fi

export ServerName=$1

echo "#################### stop $1 `date` ####################" >> /erpHome/shell/logs/serverRestart.log

/usr/WebSphere/AppServer/bin/stopServer.sh $1

syncConfig.sh

cp    /erpHome/jln.ear/erp.war/WEB-INF/web.xml /usr/WebSphere/AppServer/profiles/Dmgr01/config/cells/p55013Cell01/applications/jln.ear/deployments/jln/erp.war/WEB-INF

cp    /erpHome/jln.ear/erp.war/WEB-INF/web.xml /usr/WebSphere/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.bak

cp    /erpHome/jln.ear/erp.war/WEB-INF/web.xml /usr/WebSphere/AppServer/profiles/Dmgr01/config/cells/p510Cell01/applications/jln.ear/deployments/jln/erp.war/WEB-INF

cp    /erpHome/jln.ear/erp.war/WEB-INF/web.xml /usr/WebSphere/AppServer/profiles/AppSrv01/config/cells/p510Cell01/applications/jln.ear/deployments/jln/erp.war/WEB-INF

/usr/WebSphere/AppServer/profiles/Dmgr01/bin/GenPluginCfg.sh

updateFTPSrc.sh

. /erpHome/shell/setP.sh

echo `date` > $ERPHome/work/da/log/update/last.log

export DAHome=/home/ftpuser/pub

if ! test $(find $DAHome -type f | wc -l) -eq 0

        then

echo `date` ": Update source" >> $UpdateLog 2>&1

echo "################ Update the source ################" >> $UpdateLog 2>&1

echo $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/* >> $UpdateLog 2>&1

find $DAHome -type f -exec \\rm -e {} \\; >> $UpdateLog 2>&1

# echo "copy" >> $UpdateLog 2>&1

# mail -s "$1 update program" root < $UpdateLog

echo `date` ": Update source done" >> $UpdateLog 2>&1

        fi

updateSource.sh

. /erpHome/shell/setP.sh

$ShellHome/updateSrc.sh bin

$ShellHome/updateSrc.sh toc

$ShellHome/updateFTPSrc.sh

updateSrc.sh

. /erpHome/shell/setP.sh

echo `date` > $ERPHome/work/da/log/update/last.log

export DAHome=$ERPHome/work/da/$1

if ! test $(find $DAHome -type f | wc -l) -eq 0

        then

echo `date` ": Update source" >> $UpdateLog 2>&1

echo "################ Update the source ################" >> $UpdateLog 2>&1

echo $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/* >> $UpdateLog 2>&1

find $DAHome -type f -exec \\rm -e {} \\; >> $UpdateLog 2>&1

# echo "copy" >> $UpdateLog 2>&1

# mail -s "$1 update program" root < $UpdateLog

echo `date` ": Update source done" >> $UpdateLog 2>&1

        fi

viewHtml.sh

. /erpHome/shell/setP.sh

mv $ERPHome/access.txt /erpHome/shell/logs/access_$YYMMDD.txt

awk -F "\" -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 /erpHome/shell/htmlHead.txt > $ERPHome/public/$YYMMDD.html

awk -F "\" -f /erpHome/shell/formatHTML.awk /erpHome/shell/logs/temp2.csv >> $ERPHome/public/$YYMMDD.html

cat /erpHome/shell/htmlFoot.txt >> $ERPHome/public/$YYMMDD.html

文档

很实用的Shell脚本(实践版)

ApacheLogRotate.shecho`date`":Cleantheapachelogs">/usr/WebSphere/IHS/logs/access_log>/usr/WebSphere/IHS/logs/error_logapforwinbk.shexportDayOfWeek=`date+"%u"`cd/wasbackupcp-rf./WASBackup_"$DayOfWeek".tar./apbkarchiveOld.shexportTargetDir=/erpHome/jl
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top
来源电脑时间网址执行时间QueryStringUserID