
cuboidgraphix
User
Jan 22, 2009, 9:00 PM
Post #16 of 19
(3724 views)
|
|
Re: [KevinR] Help with Telnet commands.
[In reply to]
|
Can't Post
|
|
Using Date::Calc should be easier but sometimes its good to figure out how to do these things on your own. You're right Kevin. It just sucks when I try to learn new things and end up not using it. :( I went with your first advice and did the basic math thingie and it worked. I just wanted to use a module, but it's hard learning how to use the module. Anyways... here's my finished code. It works ... might not be the best script, but I did try to do good perl practice.
#!/usr/bin/perl # This file is the parser.pl # This is a script that will parse data from the Syslog use strict; use warnings; use Text::ParseWords; my $file = $ARGV[0] || die "Usage: $0 <filename>\n"; open my $FH, '<', $file or die "Can't open '$file' $!"; while (<$FH>) { if($_ =~ /^20/){ my ($Date, $Time, $Local, $CID1, $CID2, $CID3, $CID4, $PA, $CT, $DT) = (quotewords('\s+', 0, $_))[0,1,2,12,13,14,15,24,36,43]; my ($CID, $DIFF, $CALL, $secs1, $secs2); if($Local =~ /^Local7.Notice/){ $CID = "$CID1 $CID2 $CID3 $CID4"; $CT = substr("$CT",1,8); $DT = substr("$DT",1,8); $secs1 = (substr("$CT",0,2) * 360)+(substr("$CT",3,2) * 60)+substr("$CT",6,2); $secs2 = (substr("$DT",0,2) * 360)+(substr("$DT",3,2) * 60)+substr("$DT",6,2); $DIFF = $secs2 - $secs1; print "Date: $Date \n"; print "Time: $Time \n"; print "ConnectionID: $CID \n"; print "PeerAddress: $PA \n"; print "ConnectTime: $CT \n"; print "DisconnectTime: $DT \n"; print "TotalTime: $DIFF \n"; print " \n\n"; $CALL = "$Date,$Time,$CID$PA$CT,$DT,$DIFF\n"; my $calllog = "calllog.txt" || die "Usage: $0 <filename>\n"; open my $CL, '>>', $calllog or die "Can't open '$calllog' $!"; print $CL $CALL; close $CL; } if($Local =~ /^Local7.Error/){ my $errorlog = "errorlog.txt" || die "Usage: $0 <filename>\n"; open my $EL, '>>', $errorlog or die "Can't open '$errorlog' $!"; print $EL $_; close $EL; } } } close $FH;
|