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

Discussion in 'Perl Misc' started by Jayesh Kamdar, May 24, 2005.

  1. 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
    Jayesh Kamdar, May 24, 2005
    #1
    1. Advertising

  2. 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
    Sherm Pendley, May 24, 2005
    #2
    1. Advertising

  3. 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
    Gunnar Hjalmarsson, May 25, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,229
    Michael Borgwardt
    May 30, 2004
  2. Shun
    Replies:
    1
    Views:
    3,031
    Jon Paal
    Jul 13, 2006
  3. Replies:
    0
    Views:
    292
  4. Paulo

    Employee TimeSheet/Projects

    Paulo, Jun 16, 2009, in forum: ASP .Net
    Replies:
    2
    Views:
    895
    Gregory A. Beamer
    Jun 16, 2009
  5. Stefan Kiryazov

    Employee motivation in the software industry

    Stefan Kiryazov, Feb 5, 2010, in forum: Python
    Replies:
    0
    Views:
    284
    Stefan Kiryazov
    Feb 5, 2010
Loading...

Share This Page