Greetings Monks,

I'm in need of your assistance once again. I have the below code. I am trying to match a username to an ip address if that person had that ip at the given time. All is well when there is a definite start and stop entry in the log, but sometimes someone starts and does not stop until the next days log. What would be a good way to obtain these users?

Thanks
Dru
#!/usr/bin/perl -w use strict; my $time = '02:42:10'; my $ip = '192.168.201.57'; my ($ace_start_time,$ace_stop_time,$ace_user,$user); while (<DATA>){ if (/\b$ip\b/){ if (/Start/){ ($ace_start_time,$ace_user) = (split/,/)[1,2]; # What I tried to use, but doesn't work since it # will grab the first start entry if ($time gt $ace_start_time){ $user = $ace_user; print "$user had $ip at this time\n"; last; } } elsif (/Stop/){ ($ace_stop_time,$ace_user) = (split/,/)[1,2]; } if ($ace_start_time && $ace_stop_time){ if ( ($time gt $ace_start_time) && ($time lt $ace_stop_time) ){ $user = $ace_user; last; } } } } } __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 10/26/2004,02:34:52,lgreen,VPN_General,10.0.202.214,Start,3D70FB46,,Fr +amed,PPP,,,,,192.168.201.57,21153,192.168.17.252 10/26/2004,02:39:04,lgreen,VPN_General,10.0.202.214,Stop,3D70FB46,253, +Framed,PPP,14848,11552,160,111,192.168.201.57,21153,192.168.17.252 10/26/2004,02:40:18,cred,VPN_General,10.0.207.7,Start,3D70FB4A,,Framed +,PPP,,,,,192.168.201.57,21160,192.168.17.252

In reply to 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.