Perl one-liners
Logfile analysisAssumes a standard Apache format log file unless otherwise stated
- Print the total volume of data transferred in access_log
perl -MNumber::Format=:all -lane'$t+=pop@F;END{print format_bytes($t)}' access_logperl -ane'$t+=pop@F;END{printf"%.2fM\n",$t/2**20}' access_logperl -ane'$t+=pop@F;END{printf"%.2f%s\n",$t>2**30?($t/2**30,G):$t/2**20,M}' access_logcat access_log* | grep "06/Feb" | perl -ane'$t+=pop@F;END{printf"%.2fM\n",$t/2**20}'perl -ane'$t+=pop@F;if(eof){printf"$ARGV: %.2fM\n",$t/2**20;$t=0}' a*perl -ane'$t+=pop@F;if(eof){printf"$ARGV: %.2f%s\n",$t>2**30?($t/2**30,G):$t/2**20,M;$t=0}' a*
- Count the number of unique IP addresses in access_log
perl -lape '$_=shift@F' access_log | sort | uniq | wc -lperl -lane '$t{shift@F}++;END{print scalar keys %t}' access_logperl -lane '$t{shift@F}++;if(eof){print"$ARGV: ",scalar keys%t;%t=()}' a*
Copyright © 2003-2008 Jon Allen (JJ)
Last site update was on 20 Jul 2008 - 15:03 What's new?