Click to See Complete Forum and Search --> : Apache uptime


dgcartel
09-23-2000, 04:39 PM
Is there anything i can include in a page i have setup with apache that will state how long the server has been up.

for example in the corner or a pop-up box it can say Server uptime 00hr:00min:10sec or something like that.

Thanks

Taylor
09-25-2000, 02:21 PM
Something like this?
http://www.fgames.net/cgi-bin/box.pl

here is the l33t cgi script.
____________________________
#!/bin/sh
echo Content-type: text/html
echo
echo "<html>

<head>
<title></title>
</head>

<body bgcolor=#000000 text=#FFFFFF>

<div align=center>
<center>
<table border=0 cellpadding=0 width=500 height=311>
<tr>
<td width=6 height=21></td>
<td width=400 height=21></td>
<td width=6 height=21></td>
</tr>
<tr>
<td width=6 height=240></td>
<td width=450 height=240>
<p align=center><font size=6><b><i>Linux Box (aka |33+ S3®v3®)</i></b></font></p><br><br>
<p>$('uptime')</p>
<p><br><br>
some crap goes here in the page.
<td width=6 height=240></td>
</tr>
</table>
</center>
</div>
</body>
</html>"
---------------------------------

I am sure there is a better way to do this but I did not feel like spending much time on it and got this working quickly. Be sure to have the "" in the .cgi or .pl script.

If anyone has a better way of doing this I would be intreasted also. http://www.linuxnewbie.org/ubb/smile.gif



------------------
-Taylor

klamath
09-25-2000, 02:30 PM
That's the uptime of the system, not Apache.

------------------
- Klamath
Get my GnuPG Key Here (http://klamath.dyndns.org/mykey.asc)

Taylor
09-25-2000, 07:06 PM
Err opps. http://www.linuxnewbie.org/ubb/smile.gif I am sorry I had miss read the original post.I thought he ment how long the system was up.

That would require alittle more coding. I guess you could do it with perl though.



------------------
-Taylor

dgcartel
11-19-2000, 10:34 PM
Huh I just want something I can shove into my html...
Someone help...thanks

iDxMan
11-30-2000, 08:46 PM
Originally posted by dgcartel:
Huh I just want something I can shove into my html...
Someone help...thanks

Well. Here's a 0.04s perl hack that just might do the trick. You'll either have to run as cgi or cgi as a ssi.


#!/usr/bin/perl -w

$APACHE_COMMAND_STRING = "httpd";

$result=`ps -eo "%U %c %t"|grep $APACHE_COMMAND_STRING|grep -v grep|grep root`;

(undef,undef,$uptime) = split(/\s+/,$result);

if ($uptime)
{
print "$uptime\n";
}
else
{
print "Error: Apache is currently not running\n";
}


Ok. Change the $APACHE_COMMAND_STRING to whatever your system uses. ie: Most would fire up the httpd process, although I just noticed that Debian would envoke "apache". (ps -ef and see what's up)

You might want to add $|=1; at the top.. (output autoflush) --> and you might want to do a million other things such as error checking/etc./etc.. But I'll leave that up to you..

Linuxduck, other perl mongers -> jump in and give this guy some better code.. http://www.linuxnewbie.org/ubb/biggrin.gif

BTW, the output would look something like :

04:00 -> 4 minutes
38-20:07:21 -> 38days 20hours 7minutes 21seconds (from my main server)

I haven't done any formatting with the output .. You can always chop it up for clean/pretty/readable display..

good luck.

-r

iDxMan
11-30-2000, 08:53 PM
Seeing as how you said you wanted to run it in a little pop-up box (or in the corner of the page), then you probably want to run as a server side include..


in the html.
<!--#exec cgi="/cgi-bin/path/to/script.pl">


-r



[This message has been edited by iDxMan (edited 30 November 2000).]

klamath
11-30-2000, 10:27 PM
Impressive. But you are not a Jedi yet http://www.linuxnewbie.org/ubb/biggrin.gif

The 'ps' line doesn't work on OSs that don't use Linux's "procps" -- such as BSD or (AFAIK) most other UNIXes.

Since I can't run it on my webserver, I can't tell if it works correctly. You probably want to change the last grep line to only look for "root" at the beginning of the string -- use '^', AFAICT. And if Apache isn't running as root (for example, it's binding to port 8080), this script won't find anything.

Another way to do this is to get Apache to write to a tmp file when it starts up. If you've configured Apache to use a PID file (the PidFile directive), then you can use that. Either get the timestamp straight from that file, or use the PID in that file to find Apache's parent process easily, and then get the info from there.

------------------
- Klamath
Get my GnuPG Key Here (http://klamath.dyndns.org/mykey.asc)
Looking for an open source project to contribute to? Check out the Better Bulletin Board (http://bbb.sourceforge.net)

iDxMan
11-30-2000, 10:42 PM
Originally posted by klamath:
Impressive. But you are not a Jedi yet http://www.linuxnewbie.org/ubb/biggrin.gif



LOL http://www.linuxnewbie.org/ubb/smile.gif Thanks for the extra tips.. Perhaps it'll guide our original poster to what he needs..

-r



[This message has been edited by iDxMan (edited 30 November 2000).]