#!/perl/bin/perl.exe -w
use strict;
my $logfile = $ARGV[0] || 'C:\WINDOWS\Eicon DIVA T-A ISDN Modem Pnp.lo
+g';
my $conn = 'Connection established'; #The string identfying a logo
+n
my $hup = 'Hanging up'; #The string identifying a h
+ang up
my (@conti, @hupti, $hours, $mins, $tot_mins, $num_con);
open(INFILE, "<$logfile") or die "Error opening file: $!";
while (<INFILE>) {
#Split in mm dd yyyy hh mm ss and connect speed
@conti = (split(/ |-|:|\./))[0,1,2,3,4,5,12] if (/$conn/);
if (/$hup/ && $conti[5]) {
@hupti = (split(/ |-|:|\./))[0,1,2,3,4,5];
$num_con++; #The number of connections
$hours = $hupti[3] - $conti[3]; #Calculate hours
$hours += 24 if $hours < 0;
$mins = ($hours * 60) + ($hupti[4] - $conti[4]); #Calculate
+minutes
$tot_mins += $mins;
printf "%02d-%02d-%02d",$conti[1],$conti[0],substr($conti[2],2
+); #Date
printf " %02d:%02d:%02d Connected for ",$conti[3],$conti[4],$c
+onti[5]; #Time
printf "%04d minutes ",$mins;
printf "at %09s\n",$conti[6];
undef @conti;
}
}
close INFILE;
print "\nTotal number of connects: ";
printf "%04d \n",$num_con;
print "Total connect time: ";
printf "%06d minutes \n",$tot_mins;
print "Average connect time: ";
printf "%02d minutes \n", $tot_mins/$num_con;
|