Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


Search this Thread
Old 06-22-2005, 03:16 AM   #1
Registered: May 2004
Location: Texas
Posts: 277

Rep: Reputation: 30
server load script cgi

The script below will display your server uptime and load in text. Does anyone know how I could modify it so that it displays the load as a graphical status bar?

#!/usr/bin/perl --
print "content-type:text/html\n\n";
my $html = `uptime`;
$html =~ s/\n+//g;
if ($ENV{QUERY_STRING} =~ /js/){ print qq~uptime=('$html'); document.write(uptime);~; }
else{ print $html; }
Old 06-22-2005, 07:57 PM   #2
Senior Member
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 326Reputation: 326Reputation: 326Reputation: 326
Well, you could modify the bwbar to display load instead of network usage.

You can also create a bar-like chart using just HTML. For example, this shell CGI script extract is one I created for status on my firewall, which is then included by the target page:

# Create a bar chart to relate the rolling number of entries
# in the datafile to virus/hack activity
ENTRIES=`/bin/cat /var/www/html/datafile | /usr/bin/wc -l`
if [ $ENTRIES -gt 450 ]
if [ $ENTRIES -ge 180 ]
if [ $ENTRIES -ge 250 ]
echo "<font color=blue>"                                                        > /var/www/html/virus.html
echo "72-hour rolling automatic firewall subnet block list summary:"           >> /var/www/html/virus.html
echo "</font>"                                                                 >> /var/www/html/virus.html
echo "<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>"                            >> /var/www/html/virus.html
echo "<TR bgcolor=#AAAAAA><TH align=left WIDTH=150>Virus/Hack Activity:</TH>"  >> /var/www/html/virus.html
echo "   <TH align=left WIDTH=150><font color=darkgreen>Low</TH>"              >> /var/www/html/virus.html
echo "   <TH align=left WIDTH=150><font color=yellow>Normal</TH>"              >> /var/www/html/virus.html
echo "   <TH align=left WIDTH=150><font color=darkred>High</TH>"               >> /var/www/html/virus.html
echo "</TR>"                                                                   >> /var/www/html/virus.html
echo "<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>"                            >> /var/www/html/virus.html
echo "<TR bgcolor=#AAAAAA><TH align=right WIDTH=150>${REALENTRIES}&nbsp;</TH>" >> /var/www/html/virus.html
echo "   <TH bgcolor=${BAR} align=left WIDTH=${ENTRIES}>&nbsp;</TH>"           >> /var/www/html/virus.html
echo "   <TH bgcolor=#AAAAAA align=left WIDTH=${PAD}></TH>"                    >> /var/www/html/virus.html
echo "</TR>"                                                                   >> /var/www/html/virus.html
echo "</TABLE>"                                                                >> /var/www/html/virus.html
/bin/chmod 644 /var/www/html/virus.html
/bin/chown nobody.nobody /var/www/html/virus.html
You can see the result here. The bar changes from green to yellow to red as thresholds are passed, and the bar gets longer. It's a very simplistic way of doing it, but it gets the job done.

Last edited by macemoneta; 06-22-2005 at 08:01 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Directory listing - Calling shell script from a CGI script seran Programming 6 08-11-2005 11:08 PM
python cgi script and premature end of script headers Neruocomp Programming 1 07-28-2005 11:43 AM
cgi uaseradd script help newuser455 Programming 3 01-29-2005 06:29 PM
limiting page load frequency with a perl cgi script Metroid Programming 0 12-30-2004 10:33 PM
pipe in a cgi script lukas_z Linux - Software 0 08-10-2003 03:43 PM

All times are GMT -5. The time now is 03:10 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration