WWW Script Examples


Execute the date command via CGI.

date.cgi
#! /bin/bash

echo -e 'Content-type:text/html\n'
echo -n '<html><body><pre>'
date
echo '</pre></body></html>'

Examine some system information via CGI.

info.cgi
#! /bin/bash

echo -e 'Content-type:text/html\n'
echo -n '<html><body><pre>'
id
echo "---------------"
who
echo "---------------"
set
echo '</pre></body></html>'

Execute the date command via SSI.

date.shtml
<html>
<body>
<pre>
<!--#exec cmd="date" -->
</pre>
</body>
</html>

Display of bibTeX file malden.bib command via SSI.

bib.shtml
<html><body>
<pre>
<!--#include file="malden.bib" -->
</pre>
<hr>
Last modified: <!--#flastmod file="malden.bib" -->
</body></html>

A simple web-page hit counter.

counter.scgi
#! /bin/bash

echo -e 'Content-type:text/html\n'
echo -n '<html><body><pre>'

declare -i c
declare -i testvar
declare -i tempvar
declare -i counter
declare -i zero
declare -i one
declare -i two
declare -i three
declare -i four
declare -i five
declare -i six
declare -i seven
declare -i eight
declare -i nine
zero=0
one=1
two=2
three=3
four=4
five=5
six=6
seven=7
eight=8
nine=9
if [ -f count ]; then
    read c < count
fi
counter=1
c=c+1
testvar=c
for((testvar=c; testvar>0;testvar=testvar/10))
do
	counter=counter*10
done
counter=counter/10
for((testvar=c;counter>0; counter=counter/10))
do
	tempvar=testvar/counter
	testvar=testvar%counter
	if [ $tempvar -eq $zero ]; then
		echo -n '<img src="0.png">'
	elif [ $tempvar -eq $one ]; then
		echo -n '<img src="1.png">'
	elif [ $tempvar -eq $two ]; then
		echo -n '<img src="2.png">'
	elif [ $tempvar -eq $three ]; then
		echo -n '<img src="3.png">'
	elif [ $tempvar -eq $four ]; then
		echo -n '<img src="4.png">'
	elif [ $tempvar -eq $five ]; then
		echo -n '<img src="5.png">'
	elif [ $tempvar -eq $six ]; then
		echo -n '<img src="6.png">'
	elif [ $tempvar -eq $seven ]; then
		echo -n '<img src="7.png">'
	elif [ $tempvar -eq $eight ]; then
		echo -n '<img src="8.png">'
	else
		echo -n '<img src="9.png">'
	fi
done
echo -n $c > count

echo '</pre></body></html>'

For assignment #7, view sample results for bard.scgi and counter.scgi.