madasafish
Technical User
#for MINUTE in `cat timelist` A file with 60 numbers in ranging from 00 to 59
do
gawk -v hr=$HOUR -v min=$MINUTE -v rdate=$RDATE 'BEGIN {OFS=",";sstr=hr":"min;maxfs=0;print "DATE","TIME","COUNT","COUNT200","UNDER1","ONE2FIVE","FIVE2TEN","TEN2TWEN","TWEN2FOR","OVER40","HASHCOUNT","BLKED"}
{
if (substr ($3,1,5) == sstr)COUNT++
if (substr ($3,1,5) == sstr && ($14 == 200))COUNT200++
if (substr ($3,1,5) == sstr && ($14 == 200 && $16 < 1))UNDER1++
if (substr ($3,1,5) == sstr && ($14 == 200 && $16 >= 1 && $16 <5))ONE2FIVE++
if (substr ($3,1,5) == sstr && ($14 == 200 && $16 >= 5 && $16 <10))FIVE2TEN++
if (substr ($3,1,5) == sstr && ($14 == 200 && $16 >= 10 && $16 <20))TEN2TWEN++
if (substr ($3,1,2) == sstr && ($14 == 200 && $16 >= 20 && $16 <40))TWEN2FOR++
if (substr ($3,1,2) == sstr && ($14 == 200 && $16 >= 40 && $16 <999))OVER40++
if (substr ($3,1,2) == sstr && ($14 == 200 && $15 == "-"))HASHCOUNT++
if (substr ($3,1,2) == sstr && ($14 == 200 && $15 == 29))BLKED++
if (substr ($3,1,2) == sstr && ($14 == 200 && $15 > maxfs))maxfs=$15
}END{
print rdate,sstr,COUNT+0,COUNT200+0,UNDER1+0,ONE2FIVE+0,FIVE2TEN+0,TEN2TWEN+0,TWEN2FOR+0,OVER40+0,HASHCOUNT+0,BLKED+0,maxfs+0
}' $LOG #>> $REPORT
done
exit 0
1. Can anyone assist in putting the 1 to 60 loop within the gawk section and not on the outside like shown above. What is shown above does not produce a good report. I only want one heading.
2. I cannot get maxfs variable shown above to increment to the largest number of that 1 minute analysis.
3. Would appreciate if this code could be made more efficient. Its having to process very large files.
Here is a couple of the lines of the log file it working on.
Jul 8 12:00:25 libprx04.lang.dtv libuser: 10.91.161.3 - - [08/Jul/2011:12:00:25 +0100] "GET HTTP/1.1" 200 18742 0
Jul 8 12:00:25 libprx04.lang.dtv libuser: 10.125.60.150 - - [08/Jul/2011:12:00:25 +0100] "GET HTTP/1.1" 200 347 0
As always, thanks in advance.
Madasafish
do
gawk -v hr=$HOUR -v min=$MINUTE -v rdate=$RDATE 'BEGIN {OFS=",";sstr=hr":"min;maxfs=0;print "DATE","TIME","COUNT","COUNT200","UNDER1","ONE2FIVE","FIVE2TEN","TEN2TWEN","TWEN2FOR","OVER40","HASHCOUNT","BLKED"}
{
if (substr ($3,1,5) == sstr)COUNT++
if (substr ($3,1,5) == sstr && ($14 == 200))COUNT200++
if (substr ($3,1,5) == sstr && ($14 == 200 && $16 < 1))UNDER1++
if (substr ($3,1,5) == sstr && ($14 == 200 && $16 >= 1 && $16 <5))ONE2FIVE++
if (substr ($3,1,5) == sstr && ($14 == 200 && $16 >= 5 && $16 <10))FIVE2TEN++
if (substr ($3,1,5) == sstr && ($14 == 200 && $16 >= 10 && $16 <20))TEN2TWEN++
if (substr ($3,1,2) == sstr && ($14 == 200 && $16 >= 20 && $16 <40))TWEN2FOR++
if (substr ($3,1,2) == sstr && ($14 == 200 && $16 >= 40 && $16 <999))OVER40++
if (substr ($3,1,2) == sstr && ($14 == 200 && $15 == "-"))HASHCOUNT++
if (substr ($3,1,2) == sstr && ($14 == 200 && $15 == 29))BLKED++
if (substr ($3,1,2) == sstr && ($14 == 200 && $15 > maxfs))maxfs=$15
}END{
print rdate,sstr,COUNT+0,COUNT200+0,UNDER1+0,ONE2FIVE+0,FIVE2TEN+0,TEN2TWEN+0,TWEN2FOR+0,OVER40+0,HASHCOUNT+0,BLKED+0,maxfs+0
}' $LOG #>> $REPORT
done
exit 0
1. Can anyone assist in putting the 1 to 60 loop within the gawk section and not on the outside like shown above. What is shown above does not produce a good report. I only want one heading.
2. I cannot get maxfs variable shown above to increment to the largest number of that 1 minute analysis.
3. Would appreciate if this code could be made more efficient. Its having to process very large files.
Here is a couple of the lines of the log file it working on.
Jul 8 12:00:25 libprx04.lang.dtv libuser: 10.91.161.3 - - [08/Jul/2011:12:00:25 +0100] "GET HTTP/1.1" 200 18742 0
Jul 8 12:00:25 libprx04.lang.dtv libuser: 10.125.60.150 - - [08/Jul/2011:12:00:25 +0100] "GET HTTP/1.1" 200 347 0
As always, thanks in advance.
Madasafish