Ed: this has been sitting in my “drafts” box for a while now, so I figure I might as well just push it out.
Here’s a script I wrote to count the bandwidth used from the Apache access_log:
#!/usr/bin/perl -w
use strict;
my $access_log = $ARGV[0];
my $total = 0;
my @chunks;
open(LOGFILE, $access_log) or die "Could not open $access_log $!";
# count amount of data.
while(<logfile>)
{
@chunks = split();
if($chunks[9] =~ /\d/)
{ $total += $chunks[9]; }
}
close(LOGFILE);
# convert to human readable; 1024 * 1024 = 1048576.
$total /= 1048576;
print "Amount of bandwidth : $total MB\n";
I don’t know Perl so much, so my question may seem to you stupid,
but I have error when trying to run it :
————–
Use of uninitialized value in split at ./script.pl line 14.
Use of uninitialized value in pattern match (m//) at ./script.pl line 15.
————–
Seems like “$_” (or “_@”) is not getting any value ? …
Thanks!
Try now; I updated the post to properly display all the characters. Darn WP was stripping out angle brackets.