分析日志

debug()
{
debug="true"

if [ $debug = "true" ]
then
echo $1
fi;

}


getYesterday()
{
yesterday=
yesterday=`date -d last-day +"%Y/%m/%d"`

debug $yesterday
}

getToday()
{
today=
today=`date +"%Y/%m/%d"`
debug $today

}

initialDate()
{
getYesterday
getToday
}

getlegoHome()
{
legoHome=

if [ -f /etc/profile.d/lego.sh ]; then
. /etc/profile.d/lego.sh
legoHome=`echo $LEGO_HOME`

fi
}

initail()
{
initialDate
getlegoHome
}

#$1 means lines, $2 tarLogFile, $3 each file
#get its 20 lines after exception
getLogFromEachLine()
{
#no exception
if [ $# != 3 ]
then
return
fi;

fileName=$3
logName=$2
linewithColon=$1


debug $fileName
debug $logName

lines=
lines=`echo $linewithColon | cut -d: -f1- --output-delimiter=" "`
debug $lines

#first and last time, do nothing
for line in $lines
do
grep -i "zip" $fileName > /dev/null

#its zip file
if [ $? = 0 ]
then
endLine=$[line + 20]
zcat $fileName | sed -n "$line,$endLine p" >> $logName
else
endLine=$[line + 20]
cat $fileName | sed -n "$line,$endLine p" >> $logName
fi;
done
}

#exceptionLine begin line, $1 exceptionStartLine,$2 file names
getExceptionLines()
{
exceptionEndLine=
findIt="false"

for allLine in $alllines
do
if [ $findIt = "true" ]
then
exceptionEndLine=$allLine
break;
fi;

if [ $allLine -eq $1 ]
then
findIt="true"
fi;
done;

if [ -z $exceptionEndLine ]
then
exceptionEndLine=`cat $2 | wc -l`
fi;
}


# $1 means the dir, $2 means the tar file
getDayLog()
{ dirName=$1
cd $dirName
logName=$2
whichDay=$3
for file in `ls`
do
echo "start $file" >> $2

#get today's log
#get each line first
alllines=
alllines=`zgrep -n "$whichDay" $file | awk -F : '{print $1}'`
exceptionLines=
exceptionLines=`zgrep -n "$whichDay" $file | grep -i exception | awk -F : '{print $1}'`

for exceptionLine in $exceptionLines
do
getExceptionLines $exceptionLine $file
grep -i "zip" $file > /dev/null

if [ $? = 0 ]
then
zcat $file | sed -n "$exceptionLine,$exceptionEndLine p" >> $logName
else
cat $file | sed -n "$exceptionLine,$exceptionEndLine p" >> $logName
fi;

done;

done

}


getLog()
{
getDayLog $1 $2 $today
getDayLog $1 $2 $yesterday
}


doAll()
{
initail
#feLog
getLog $legoHome/Runtime/Tomcat6/logs /root/feLog
#getLog $legoHome/Runtime/LegoRuntime/logs /root/beLog
#getLog $legoHome/Runtime/LegoRuntime/logs/webnmslog /root/webNmsLog
}

doAll
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值