Hello Great and Divine Monks,

I once again must beseech you for your aid and ask that you bestow upon me a small fraction of your boundless knowledge. I have partaken on a humble quest but have stumbled near the end.

I am seeking to calculate the length of sessions by scanning a logFile (logFile.txt). It's an apache log file and I have used other versions of this crude script successfully in the past. The one big change here being that I must now look through the file a second time for the last occurrence of the session ID.

To this end I have posted my writing below. Currently the script works only on compressed files (with slight modification) or if I remove/comment out the FILELEN file handle. If I run it as shown below it will simply spin (running from a Jenkins env) with no errors and no output. Please forgive me for showing such ugliness to your divine eyes. It is only out of great necessity that I do so.

#!/usr/bin/perl use strict; use warnings; use DBD::mysql; use File::Find; use File::Find::Rule; use POSIX qw(strftime); use PerlIO::gzip; use DateTime (); use Date::Parse qw(str2time); #Get yesterdays date my $epoc = time() - 86400; # one day before of current date. my $yesterday = strftime "%F", localtime($epoc); #REGEX Patterns my $pattern = '(\d+-\d+-\d+ \d+:\d+:\d+).*login:(\S+).*UID:(\S+).*sess +ion:(\S{32}).*type:(\d).*InstID:(\S+)'; my $pattern_session = '(\d+-\d+-\d+).*'; my $output_file= 'FileList_with_Length.txt'; open OUTPUT, ">$output_file"; #Locate Files my $dir = $ARGV[0]; my $ffr_obj = File::Find::Rule->file() ->name( "logFile.txt" ) ->maxdepth( 5 ) ->start ( $ARGV[0] ); while (my $file = $ffr_obj->match() ) { if($file =~ /\/net\/bard2\/home\/bca\/logs\/ilrn-(east|west|sjc|cv +g)(\d+)\/logFile.txt/) { my $node = $2; my $pool = $1; print "In File: $file\n"; open FILE, "< $file" or die $!; while(<FILE>) { if ($_ =~ /$pattern/) { my $currentline = $. ; my $currentsession = $4 ; my $starttime = $1 ; #Sets date and time when first +session ID found my $endtime = 0; #Will hold date and time when +last session ID found my $duration = 0; #Get Sesion Length my $lastseen = 0; #If > 100000 will assume session +has ended open FILELEN, "< $file" or die $!; #open FILELEN, "<:gzip", "$file" or die $!; while (<FILELEN>) { #Skip all lines up to current line (where session +ID was first seen) next if (1..$currentline); if ($_ =~ /(\d+-\d+-\d+ \d+:\d+:\d+).*$currentsess +ion/) { $lastseen = 0; $endtime = $1; #Sets endtime to last date a +nd time seen } else { if($lastseen < 100000) { $lastseen++; } if($lastseen >= 100000) { #Exit if 100,000 +lines were searched with out seeing any further next; #of the session i +d } } } close FILELEN; $duration = str2time($endtime) - str2time($starttime); + #convert to epoch time and subtract to get length in seconds if($duration > 5) { print OUTPUT "$1\t$2\t$3\t$4\t$ +5\t$6\t$duration\n" ; print "$1\t$2\t$3\t$4\t$5\t$6\t$duration\n" } + } } close FILE; } } close OUTPUT;
I thank you again for your blessings.
UPDATE: Sample of the log files. I do apologize, I meant to include this originally.

2014-09-28 16:49:55" INFO com.xxx.session.Session.login login:someone@email.com UID:1263498014 session:647D67F6F741B57C8ACDC05F13D1C3C0 browser:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36 type:1 remote-ip:00.000.00.000 InstID:003675 region:US|| Skin:UNIVERSITY OF SomeSchool SessionObjectID:396640419

2014-09-28 16:51:08" INFO AssignmentSessionLifecycleLogger Start UserActionStart instID:003675 userID:1263498014 userLogin:some@email.com assignmentID:1277035616 assignmentResultsID:1883245099 sessionID:647D67F6F741B57C8ACDC05F13D1C3C0 requestURI:/xxx/takeAssignment/takeCovalentActivity.do

2014-09-28 20:10:21" INFO AssignmentSessionLifecycleLogger Stop SessionCloseCleanup instID:003675 userID:1263498014 userLogin:some@email.com assignmentID:1277035616 assignmentResultsID:1883245099 sessionID:647D67F6F741B57C8ACDC05F13D1C3C0 requestURI
-Kevin Murphy

In reply to Suspect FH issues by kdmurphy001

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.