Calculating time of employee session from the log date/time stampusing perl

J

Jayesh Kamdar

Hi,

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

Thanks,
Jayesh
 
S

Sherm Pendley

Jayesh said:
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

Regexes would be useful for splitting up the lines of the log:

perldoc perlretut
perldoc perlre

And Date::Manip would help parse and compare the time/date stamps.

sherm--
 
G

Gunnar Hjalmarsson

Jayesh said:
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";
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top