We know because the IP check run every 5 minutes by cron, and if it has no run within 5:01 minutes then the computer is off, or the script isn't working. But we should assume that the computer is off is there is not a record for that 5 minute slot. Alternatively we could write another line into the log when the computer shuts down.
Watty > -----Original Message----- > From: John Holmes [mailto:[EMAIL PROTECTED] > Sent: 15 August 2004 01:52 > To: Watty > Cc: [EMAIL PROTECTED] > Subject: Re: [PHP] Log parsing > > Watty wrote: > > > I would like to do some thorough availability reports, so I started by > > writing the result of the bash script to a log file. I want to parse the > > log file to give me availability reports. The log file is in the form: > > 08/14/04 09:10:01 [TAB] S - when the IP > > check returns OK > > 08/14/04 09:10:01 [TAB] U - when the IP need > > to be synchronised > > > > The process does not run when the computer is not on, so that needs to > > be taken into consideration. > > Is there any entry for when the script/computer is started or stopped? > If not, you're not going to be able to determine the actual uptime. If > one entry is S, then two hours pass and an entry is U, how do we know if > the computer was on or off during that time? > > Basically how this is going to work: > > 1. Read first two lines, $line[1], $line[2], using fgets() > 2. Use strtotime() to convert timestamps and subtract > to determine the elapsed time between them > 3. Add difference to either $U_time or $S_time based > upon status (S or U) in $line[1] > 4. Set $line[1] = $line[2] > 5. Read next line of file into $line[2] > 6. GOTO #2 > > Then you'll have total $U_time and total $S_time and you can calculate > your percentages from there. > > -- > > ---John Holmes... > > Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ > > php|architect: The Magazine for PHP Professionals - www.phparch.com > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php