Shell CGI

Published: Sunday, Apr 27, 2008 Last modified: Monday, May 10, 2021

For simple scripts shell is pretty good. It’s a sane choice if you plan on embedding a Web application on a device, as PHP is a bit of a PIG.

The Apache2 configuration with .htaccess is straight forward:

Options +ExecCGI
AddHandler cgi-script .cgi

However if you are embedding CGI, use a light httpd like nostromo httpd.

The important element with HTML shell CGI scripts in to ensure you have “Content-Type: text/html” in there with a couple of carriage returns.


title="Shell CGI"

cat <<END
Cache-Control: no-cache
Content-Type: text/html

<!DOCTYPE html>
        <meta charset="utf-8" />

wget &> /dev/stdout || echo "Permission denied"

cat <<END

/dev/stderr outputs to /var/log/apache2/error.log so you need redirect wget output to stdout as I do in this case.