Jayesh Kamdar wrote:
> I would appreciate if someone can point me to any perl command/module
> that will let me calculate the session of the person was logged on to
> corporate server. I have included a sample of log.
>
> employee XXXXX logged in via VPN3000 at 01:37:34 on 04/18/2005 from
> 111.111.1.111
> employee XXXX logged out of VPN3000 at 08:12:46 on 04/18/2005
use Date::Calc 'Delta_DHMS';
my (%in, %sessions);
sub timeparse {
local $_ = shift;
my @date = m{at\s+(\d+)

\d+)

\d+)\s+on\s+(\d+)/(\d+)/(\d+)};
[ @date[5,3,4,0,1,2] ];
}
while ( <> ) {
if ( /^employee\s+(\S+)\s+logged\s+in/ ) {
$in{$1} = timeparse($_);
} elsif ( /^employee\s+(\S+)\s+logged\s+out/ and
exists $in{$1} ) {
push @{ $sessions{$1} },
[ Delta_DHMS( @{ delete $in{$1} }, @{ timeparse($_) } ) ];
}
}
for my $empl ( keys %sessions ) {
print "$empl sessions:\n";
for ( @{ $sessions{$empl} } ) {
printf " %d days %d hours %d min %d sec\n", @$_;
}
print "\n";
}
--
Gunnar Hjalmarsson
Email:
http://www.gunnar.cc/cgi-bin/contact.pl