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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |