分析日志
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