Solution: Webpage Showing Openhab Log Contents

I developed a simple bash cgi script to display the contents of the (OH3) openhab.log on my web browser. I thought I’d share it. I am running on linux but this should work on other platforms.

Create the code file in /usr/lib/cgi-bin/. Mine is called openhablog.cgi.
Make sure you’ve enabled cgi in your webserver.
Do a sudo chmod +x to the file.
In your browser: http:///cgi-bin/openhablog.cgi
The script also removes the always repeating Web Socket warning. It reports the log in reverse order, latest on top. It has a refresh button to reload the log with the latest.

# This cgi reports openhab log

echo "Content-type: text/html"
echo "<html>"
echo '<title>Openhab Log</title>'
echo '<body style="background-color:#B8B8B8;">'
echo '<center style="color:blue; font-size:20px"><b>Opehab Log</b><br>'
echo "$(date +'%m-%d-%Y %r')<br><br>"
echo '<button type="button" id="mybutton" style="font-size:20px; background: darkcyan;color:white;" '
echo ' onClick="window.location.reload()">Refresh</button><br><br>'
echo '<textarea id="openhab_log" name="openhab_log" rows="44" cols="180" '
echo 'style="font-size:16px; background: black;color:white;">'
tac /var/log/openhab/openhab.log | grep -v 'Web Socket'
echo '</textarea>'
echo '</body></html>'
1 Like

could you elaborate what benefits this has over frontail?

I tried frontail and kept getting runtime errors. I decided it was easier to just take this approach.

I like the fact that the log remains constant for inspection yet I can refresh the contents. It works for me.

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.