#!/usr/bin/perl -w if($#ARGV < 0) { print "Usage: ckbw month\nPrints the bandwidth used in a month.\nUse shorthand notation (ie, Jan, Feb, Mar)\n"; exit(1); } my ($cuser, $month); $cuser = $ENV{"USER"}; $month = $ARGV[0]; #find all of the log files for the user system("/bin/cat /home/".$cuser.".logs/*.access.log* 1>/tmp/ckbw-".$cuser." 2>/dev/null"); open(LOGFILE, "/tmp/ckbw-".$cuser); my @logs = ; close(LOGFILE); unlink("/tmp/ckbw-".$cuser); my $total = 0; foreach $line (@logs) { @linesep = split(/ /, $line); #check the month if($linesep[3] =~ m/($month)/i) { #make sure there is an actual value if($linesep[9] =~ m/\d/) { $total += $linesep[9]; } } } print "Bandwidth totals:\n"; print $total." bytes\n"; $total /= 1024; print $total." KB\n"; $total /= 1024; print $total." MB\n"; $total /= 1024; print $total." GB\n";