I'm going to show how to executes cgi-bins using this web server.

In a recent post I showed how to install the Monkey http web server on Raspbian so I'll start this post from a working installation. (I'll suppose monkey server has been installed in the /home/pi/monkey-1.2.0/ directory)

The script I want to run is a bash script that reads the Raspberry Pi temperature and prints out the read value.
I described this script in another post (take a look here).

Anyway the source code is the following:

#!/bin/bash
$(cat /sys/class/thermal/thermal_zone0/temp > aux)
TEMP=$(awk '{print $1}' aux)
rm -f aux
echo "Content-type: text/html"
echo ""
echo "<html><head><title>Raspberry Temperature</title></head><body>"
echo "Current temperature is $TEMP <br>"
echo "</body></html>"

temperature_monitoring


Name this script "temp.cgi" and change file mode bits as follows:


$ chmod +x temp.cgi

 

as advices by Mika (linkedin): to spare SD card change the script, in this way you'll avoid the redirection on a file

echo "Content-type: text/html" 
echo "" 
echo "<html><head><title>Raspberry Temperature</title></head><body>" 
echo "Current temperature is $(awk '{print $1}' /sys/class/thermal/thermal_zone0/temp)<br>" 
echo "</body></html>" 

 

 

Create the directory cgi-bin

$ mkdir /home/pi/monkey-1.2.0/htdocs/cgi-bin

 

Move the script into the cgi-bin dorectoy

$ move temp.cgi /home/pi/monkey-1.2.0/htdocs/cgi-bin

With your favourite editor open the /home/pi/monkey-1.2.0/conf/plugins.load configuration and change the line

 

    # Load /home/pi/monkey-1.2.0/plugins/cgi/monkey-cgi.so
in 
    Load /home/pi/monkey-1.2.0/plugins/cgi/monkey-cgi.so

    
Remeber, no tabs are allowed and before the Load command there must be 4 blank spaces.


Now run the Monkey server

$ /home/pi/monkey-1.2.0/bin/monkey -D

 

Just to try, point your web browser to http://127.0.0.1:2001/cgi-bin/temp.cgi


That's all.