Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Calculating time of employee session from the log date/time stampusing perl

Reply
Thread Tools

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

 
 
Jayesh Kamdar
Guest
Posts: n/a
 
      05-24-2005
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
 
Reply With Quote
 
 
 
 
Sherm Pendley
Guest
Posts: n/a
 
      05-24-2005
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


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--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      05-25-2005
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to verify if an employee truely has an MCSE =?Utf-8?B?Qm9kaW5lOTU=?= Microsoft Certification 8 01-15-2010 06:52 AM
Vista: "Calculating time remaining" takes long time on any fileaction. Even with all suggested KB patches installed Peter Computer Support 2 12-15-2007 12:57 AM
Calculating the log of a number Protoman C++ 21 09-17-2005 04:56 PM
Establishing a VPN connection to an at home employee Paul Cisco 4 02-13-2004 07:39 AM
Checking whether an employee is microsoft certified. Stuart p Microsoft Certification 4 10-17-2003 06:22 AM



Advertisments