Web Hosting Talk







View Full Version : Uptime Script


David@Digisurge
07-20-2001, 06:20 PM
Does anyone know of a cgi or PHP script that can be called and returns the currently monthly uptime %. I only want the monthly % nothing else.

shadowbreed
07-20-2001, 06:31 PM
oops i think i need to get some sleep i didn't even see you wanted the %

David@Digisurge
07-20-2001, 06:37 PM
Thats ok I understand. I have been up for 27 hours now:(

Go ahead and post your orginal post it may still be usefull.

Tim Greer
07-20-2001, 06:44 PM
#!/usr/bin/perl -w
print "Content-type: text/html\n\n";
print "Uptime is: ", (split(/,/, (split(/up/, `/usr/bin/uptime`))[1]))[0];

Actually, I should recode that part, as that will only show the day or only minute, to show both, use this code:

#!/usr/bin/perl -w
print "Content-type: text/html\n\n";
@uptime = (split(/,/, (split(/up/, `/usr/bin/uptime`))[1]))[0,1];
$uptime[1] = '' if ($uptime[1] =~ /users?$/);
print "Uptime is: @uptime\n";

This way, it'll work with both just the minutes, just the day, or minutes and days, or whatever the uptime is, without any screw ups.



I too misread your post. I thought you wanted just the days/time up, and not anything else. I'm not exactly sure how you can get a monthly percentage from the uptime. I mean, you'd have to keep track of how many days the script has been running, how long the server's been up, how long it was up before that, add them all together, divide it by the month and days and what month it is, and get a percentage from that. I thought your question was about something else, hence the code above. There's got to be a better way to get the monthly percentage, than from the uptime and doing it that way.

David@Digisurge
07-20-2001, 06:46 PM
Wow Tim,

Thats just about what I was looking for. Thank you.

Nice Sig :D

Tim Greer
07-20-2001, 06:49 PM
No problem, just after posting, I see that it wasn't quite what you're looking for, exactly, but at least you'll have the days, hours and minutes to be able to do the math with. But, what happens if the system goes down? The uptime is reset and you start all over. You're going to need to keep track somehow, and have it saved somewhere, and hope it saves it before the system goes down, if it did.


WOW, I MUST BE A COMPLETE IDIOT! I misread it both times, thinking (don't ask me WHY!?) that you literally meant the "uptime" of the system, as in the system's uptime. Oops, oops, ooops.. I don't see how I could have possibly missed that! Forget I posted anything, I don't know how I could have so grossly misread your question. Sorry about that.