[ale] [OT] how do I monitor the "weather" in my computer room
Alex Carver
agcarver+ale at acarver.net
Fri Jun 7 01:48:16 EDT 2013
On 6/6/2013 20:38, Ron Frazier (ALE) wrote:
ough:
>
> A) If I let nc run on port 80, I get a properly displayed web page in
> the browser. If I don't, I get a display as if I'm looking at the page
> source.
This is because netcat does not send the HTTP headers. When it is on
port 80 (the HTTP port), your browser simply assumes that anything
coming in is HTML. If you put it on another port, it looks for the
headers to determine the data type and appropriate rendering. Since
there are no headers, you get raw data rendering (text). You would need
to either create the headers in the file or use some web server to
actually serve the data on a different port.
Try adding "Content-Type: text/html" to the very top of your output file
(before the <HTML> tag) followed by one blank line:
echo "Content-Type: text/html" > outputfile
echo "" >> outputfile
It should render as HTML from a different port.
>
> B) The sudo authorization for the nc command expires and then my web
> page no longer loads.
You don't need sudo for netcat on a non-reserved port (port numbers
above 1024). You would only need it for port 80.
> C) I don't have an autostart sequence running yet.
>
> D) Sometimes, if I happen to retrieve the file while it's being written,
> I get an incomplete result.
This would be an expected flaw in the implementation with almost any web
server. You would have to create a temporary file first, then at the
last moment copy the temporary file to the permanent location (since the
copy will be fast versus the writing of several command outputs). The
only true way to avoid this is with CGI scripting to execute the script
at time of request.
> E) I cannot CTRL-C to terminate the window with the nc running in it. I
> have to force close that window.
Start it as a subshell. The script should be:
#!/bin/bash
#this file is named micro-netcat-httpd.sh
while true;
do
nc -l 56789 < temperature.html;
done
Save to a file, set the executable bit then call the file:
./micro-netcat-httpd.sh &
Now you can find and kill it later (search for it within the ps process
listing).
More information about the Ale
mailing list