bash - Oneliner to calculate complete size of all messages in maillog -
ok guys i'm @ dead end here, don't know else try...
i writing script e-mail statistics, 1 of things needs calculate complete size of messages in maillog, wrote far:
egrep ' hostname sendmail\[.*.from=.*., size=' maillog | awk '{print $8}' | tr "," "+" | tr -cd '[:digit:][=+=]' | sed 's/^/(/;s/+$/)\/1048576/' | bc -ql | awk -f "." '{print $1}'
and here sample line maillog:
nov 15 09:08:48 hostname sendmail[3226]: oaf88gwb003226: from=<name.lastname@domain.com>, size=40992, class=0, nrcpts=24, msgid=<e08a679a54da4913b25adc48cc31dd7f@domain.com>, proto=esmtp, daemon=mta1, relay=[1.1.1.1]
so i'll try explain step step:
first grep through file find lines containing actual "size", next print 8th field, in case "size=40992,".
next replace comma characters plus sign.
then delete except digits , plus sign.
then replace beginning of line "(", , replace last plus sign ")" followed "/1048576". huge expression looking this:
"(1+2+3+4+5...+n)/1048576"
because want add individual message sizes , divide result in mb.
the last awk command when decimal number don't care precision print part before decimal point.
the problem is, doesn't work... , swear working @ 1 point, expression long bc handle?
thanks if took time read through :)
i think one-line awk
script work too. matches line egrep pattern matches, lines splits eighth record = sign , adds second part (the number) sum variable. when sees end of file prints out value of sum/1048576 (or byte count in mibibytes).
awk '/ hostname sendmail\[.*.from=.*., size=/{ split($8,a,"=") ; sum += a[2] } end { print sum/1048576 }' maillog
Comments
Post a Comment