Hello...

I have a question to ask about figuring elapsed time... I am writing a script to read log files of a backup software package...

The log files that I am parsing through are ASCII text files... I have extracted the information that I need, and have produced the

output that I desired... Last week I used this knowledge base forum and received many helpful replies... I have found a glitch in my

logic... I thought that I had figured out how to show the elapsed time of a backup job (start and end time extracted from the log files

I mentioned earlier)... My script is quite long so I cannot post the whole thing... Today I went back to paper and tried to go through

the logic of what I wanted to accomplish... As I started to figure out how to track elapsed time when a backup job runs past midnight

and into the next day (my end time would be smaller than my starttime) ... Then, I found a new whole in the logic... How to transverse a

month end... when the condition will exist that my start date is less than my end date... There is also the condition that will exist when

I have a month end job that crosses midnight... (I convert to total seconds of elapsed time)

Here is a example of what I have so far:

%months = qw(January 01 February 02 March 03 April 04 May 05 June 06 J +uly 07 August 08 September 09 October 10 November 11 December 12); # start if ($logfile[$i] =~ /\bJob started:/) { chomp ($tempstring = $logfile[$i]); #datetemp[0] --> Mo +nth $tempstring =~ s/Job started: //; #datetemp[1] --> Da +y $tempstring =~ s/\w*, //; #datetemp[2] --> Ye +ar $tempstring =~ s/,//; #datetemp[3] --> Ho +ur (converted to 24) $tempstring =~ s/:/ /; #datetemp[4] --> Mi +nute : Seconds $tempstring =~ s/at //; #datetemp[5] --> AM + / PM @datetemp = split (/ /, $tempstring); $datetemp[0] = $months{$datetemp[0]}; if ($datetemp[5] eq "PM") { $datetemp[3] = $datetemp[3] + 12;} if ($datetemp[5] eq "AM") { if ($datetemp[3] eq 12) { $datetemp[3] = 0;}} $start = $datetemp[2] . "/" . $datetemp[0] . "/" . $datetemp[1] . " " . $datetemp[3] . ":" . $datetemp[4]; $stime = ($datetemp[3] * 60) + $datetemp[4] ; # <-- convert +to minutes } # I could use: $stime = ($datetemp[3] * 360) + ($datetemp[4] * + 60) # <-- convert to seconds # end if ($logfile[$i] =~ /\bJob ended:/) { chomp ($tempstring = $logfile[$i]); $tempstring =~ s/Job ended: //; $tempstring =~ s/\w*, //; $tempstring =~ s/,//; $tempstring =~ s/:/ /; $tempstring =~ s/at //; @datetemp = split (/ /, $tempstring); $datetemp[0] = $months{$datetemp[0]}; if ($datetemp[5] eq "PM") { $datetemp[3] = $datetemp[3] + 1 +2;} if ($datetemp[5] eq "AM") { if ($datetemp[3] eq 12) { $datetemp[3] = 0;}} $end = $datetemp[2] . "/" . $datetemp[0] . "/" . $datetemp[1] . " " . $datetemp[3] . ":" . $datetemp[4]; $etime = ($datetemp[3] * 60) + $datetemp[4]; # <-- convert + to minutes } # I could use: $stime = ($datetemp[3] * 360) + ($datetemp[4] + * 60) # <-- convert to seconds # time of job in seconds $sectime = ($etime - $stime) * 60; # <-- convert to seconds # sectime = ($etime - $stime) #if already in seconds

The problem is that it's not complete and it does not work... I I'm having trouble developing the logic behind...

I put together $start and $end from parsing the logfile now I need some help with the logic of elapsing the time...

If anyone can help me out please let me know... I can try and clarify this incomplete thought listed above...

Darrick...

dbrock05@comcast.net

udpate (broquaint): re-formatted code and added <code> tags in appropriate places.
update 2 (broquaint): added <readmore> tag


In reply to Elapsed date and time by dbrock

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.