#!/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;
In reply to modem log
by flacour
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.