Web Status Page

I would like to have a webpage display sysctl output for OneWire on my local network.

sysctl dev.ow_temp.0.temperature
sysctl dev.ow_temp.1.temperature
sysctl dev.ow_temp.2.temperature
sysctl dev.ow_temp.3.temperature

What are my options? I would like to use a lightweight solution.
lighttpd is my prefered server.

I see PHP has a shell_execute function.

I only want static content.
How to display shell command output in html?
 
I am guessing you can't just write the html file from a shell.
Yes that approach works. I see awk use some.

I don't know bash well but this sounds like what I want.
 
I use net-mgmt/mrtg to monitor the CPU temperature and network bandwidth usage at my Openbsd firewall. I use SNMP for this, but MRTG can graph the output of arbitrary scripts, too:
 
What you are writing is de-facto a CGI program. The lighttpd server supports those. Those can be written in many languages. I personally prefer Python, but I've also done Perl; PHP is sort of the industry standard. All of those languages have a functionality like "system" to run an arbitrary program. Some of them also allow you to do a sysctl directly, without invoking another program throught system().
 
Just for a technical prelude I want to try to use csh instead of bash for a one line web server.
I am infatuated with the idea.
The most simple web server possible with a tool in base. Great way to learn from the bottom up.

I am not good at bash to csh conversion so please bear with me for this distraction.

My sources:
 
All you have to do is print '200 OK' and a couple of headers, then you can just print HTML. You can easily test this on the command line without using a webserver.
 
I am using the sh interactive shell under tcsh.
This command almost works but I am missing the netcat -q flag in FreeBSD.
Once I 'control-c' the command the webpage is filled.
while true ; do { echo -e 'HTTP/1.1 200 OK\r\n' ; cat index.html ; } | nc -l 8080 ; done
 
Code:
IFS='
'
nc -lk [ip] [port] | while read line; do
    if [ "$line" = "GET HTTP/1.1"] #the get request
        while read unused; do :; done #clean request header
        print "HTTP/1.1 200 OK\r\n\r\n"
        printf "<html>temp1=%s.." $(sysctl -n hw... hw...)
    fi
done

Something of the sort should work fine (havn't tested).
 
Code:
IFS='
'
nc -lk [ip] [port] | while read line; do
    if [ "$line" = "GET HTTP/1.1"] #the get request
        while read unused; do :; done #clean request header
        print "HTTP/1.1 200 OK\r\n\r\n"
        printf "<html>temp1=%s.." $(sysctl -n hw... hw...)
    fi
done

Something of the sort should work fine (havn't tested).
Doesn't work at all. It's a snake that bite's his tail.. Post #6 is prefered unless you can manage to redirect to/from some fifo.
 
Code:
[what@bsd]~> cat header.html serv.sh foot.html
HTTP/1.1 200
Server: nc
Content-Type: text/html; charset=UTF-8

<!DOCTYPE html>
<html>
        <body>
#!/bin/sh

body()
{
        while read l; do
                echo "<p>$l</p>"
        done
}

while :; do
        sysctl dev.cpu | grep temperature | body > body.html
        cat header.html body.html foot.html | \
                nc -lN 8000
done
        </body>
</html>

Here we go. Somehow I didn't manage to make this work earlier.. Does the browser have some syntax check now?
It seems that getting a 'proper' html code helps a lot.

With the '-N' option the server stops after the client read the 'nc' buffer, which means that when you reload the page, the resulting html code will be the one generated when 'nc' was first issued or the page was last reloaded.
 
Back
Top