When you host your own web server, the CGI protocol allows you to do server-side programming in any language you like; including Bash.
Here's a simple example that serves a web page that displays the current date and time, and refreshes every 10 seconds. Put the Bash script below in a file named test.cgi
in the cgi-bin
folder (on Linux/Apache: /usr/lib/cgi-bin
) and make it executable (chmod +x test.cgi
). The page's URL is: http://MyWebServer/cgi-bin/test.cgi
#!/bin/bash
cat << EOT
content-type: text/html
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<meta http-equiv="refresh" content="10" />
</head>
<body>
$(date)
</body>
</html>
EOT
Please note: the empty line below content-type
is relevant in the CGI protocol.
Replace date
by your own Bash script; make sure it outputs something that resembles valid HTML. This means you need to take some effort to add HTML tags for your markup, and HTML-encode some characters (< > &
) in your content.