Parse Webalizer logs for bandwidth consumption

chris (2003-07-01 00:17:04)
2890 views
0 replies
Yet another odd one - somebody who needed to be able to parse the html files generated by webalizer.. and produce just a single number- he total bandwidth consumed that month.

So I knocked up this PERL example, which parses the log for my webcam on my webserver at home. You'll have to change the path if you want to test it yourself, then just run the script within a shell and you'll get a single value back. Easy peasy.

#!/usr/bin/perl
use strict;
use warnings;
 
my $log="/export/webcam/www/admin/stats/usage_200306.html";
my $watch=0;
open(FILE,"$log");
 
while(){
        if($watch==1){
                /(d+)/ && printf("$1") && ($watch=0 && next);
        }
        /TotalsKBytes/ && $watch++;
}
comment