Dru,
You might have to also consider what to do if they don't have a "Start" (the IP was already taken at the start of the log). The following code should do what you want though it isn't very elegant.
#!/usr/bin/perl use strict; use warnings; use constant USER => 0; use constant TIME => 1; my ($user, $start, $stop) = Get_User( time => '02:42:10', ip => '192.1 +68.201.57' ); print "$user had 192.168.201.57 from Start: ", $start, " until Stop: " +, $stop, "\n"; sub Get_User { die "Incorrect number of parameters" if @_ % 2; my %find = @_; die "time & ip are required parameters" if ! exists $find{time} || + ! exists $find{ip}; my $pos = tell DATA; my ($user, $start, $stop); my %session; while ( <DATA> ) { my ($time, $uid, $action, $sid, $ip) = (split /,/)[1, 2, 5, 6, + 14]; next if $ip ne $find{ip}; $session{ $sid }{$action} = [ $uid, $time ]; } seek DATA, $pos, 0; # assume we have both for ( values %session ) { next if ! exists $_->{Start} || ! exists $_->{Stop}; if ( $_->{Start}[TIME] le $find{time} && $_->{Stop}[TIME] ge $ +find{time} ) { return $_->{Start}[USER], $_->{Start}[TIME], $_->{Stop}[TI +ME]; } } # assume we only have a stop for ( values %session ) { next if exists $_->{Start}; if ( $_->{Stop}[TIME] ge $find{time} ) { return $_->{Start}[USER], '--:--:--', $_->{Stop}[TIME]; } } # assume we only have a start for ( values %session ) { next if exists $_->{Stop}; if ( $_->{Start}[TIME] le $find{time} ) { return $_->{Start}[USER], $_->{Start}[TIME], '--:--:--'; } } return qw(NONE --:--:-- --:--:--); } __DATA__ 10/26/2004,00:02:41,jdoe,VPN_General,10.0.218.253,Stop,3D70FA44,3559,F +ramed,PPP,390032,3722000,4120,5306,192.168.201.57,20824,192.168.17.25 +2 10/26/2004,00:03:42,bsmith,VPN_General,10.0.76.203,Start,3D70FA86,,Fra +med,PPP,,,,,192.168.201.57,20925,192.168.17.252 10/26/2004,00:23:03,bsmith,VPN_General,10.0.76.203,Stop,3D70FA86,1161, +Framed,PPP,1136608,8358544,8534,10609,192.168.201.57,20925,192.168.17 +.252 10/26/2004,00:23:16,syoung,VPN_General,10.0.132.222,Start,3D70FA99,,Fr +amed,PPP,,,,,192.168.201.57,20944,192.168.17.252 10/26/2004,02:34:44,syoung,VPN_General,10.0.132.222,Stop,3D70FA99,7886 +,Framed,PPP,432752,497712,2888,2665,192.168.201.57,20944,192.168.17.2 +52

Cheers - L~R


In reply to Re: Grabbing a Username from an Unfinished Log File by Limbic~Region
in thread Grabbing a Username from an Unfinished Log File by Dru

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.