Below is that random number generator put in to CGI form to run under Apache.
It returns grey levels in a table to provide a visual confirmation of it's output.
If you make the effort to try this code, please leave a short comment.
It's part of a effort to demonstration the use of BASH in making CGI based Applications.
#!/bin/bash
echo "Content-type: text/html"
echo
echo "<html><body>"
echo "<table border=2 cellpadding=2 cellspacing=2>"
target=localhost
c=0
while [ $c -lt 32 ]
do
c=$[$c+1]
echo "<tr>"
{
echo "obase = 16"
ping -c 32 -i 0.2 $target |\
grep "time=" |\
sed \
-e 's/[a-z \.(),_:+=]//g' \
-e 's/\(.\)/\1+/g' \
-e 's/^\(.*\)+$/(\1)% 16/'
} |\
bc |\
awk '{print "<td bgcolor=\"#"$1$1$1$1$1$1"\">"$1"</td>" }' |\
tr -d '\n'
echo "</tr>"
done
echo "</table>"
echo "</body></html>"
echo "Content-type: text/html"
echo
echo "<html><body>"
echo "<table border=2 cellpadding=2 cellspacing=2>"
target=localhost
c=0
while [ $c -lt 32 ]
do
c=$[$c+1]
echo "<tr>"
{
echo "obase = 16"
ping -c 32 -i 0.2 $target |\
grep "time=" |\
sed \
-e 's/[a-z \.(),_:+=]//g' \
-e 's/\(.\)/\1+/g' \
-e 's/^\(.*\)+$/(\1)% 16/'
} |\
bc |\
awk '{print "<td bgcolor=\"#"$1$1$1$1$1$1"\">"$1"</td>" }' |\
tr -d '\n'
echo "</tr>"
done
echo "</table>"
echo "</body></html>"
Below is a sample of the output.
D | 8 | 9 | B | F | C | D | B | 0 | 7 | A | E | E | F | B | B | F | 0 | 2 | 8 | F | 7 | E | 1 | F | B | E | 4 | 1 | 0 | F | A |
8 | 6 | D | E | F | A | F | 5 | C | A | C | C | 9 | E | C | D | B | 0 | E | E | B | 7 | F | E | D | D | E | 2 | 6 | E | A | D |
B | D | C | 9 | 0 | 9 | 2 | D | F | 7 | D | A | B | 0 | A | C | 1 | F | 5 | A | D | 0 | D | F | E | 3 | F | 2 | 6 | A | 7 | F |
8 | 8 | F | E | A | D | 6 | C | 1 | 6 | D | 6 | A | A | 0 | D | B | 2 | 2 | 6 | A | E | 9 | A | B | 3 | 0 | D | E | B | F | 8 |
5 | E | D | A | 0 | F | A | E | C | A | C | E | 9 | E | C | C | 3 | D | F | 7 | B | 8 | D | 0 | F | 1 | E | C | E | 8 | C | E |
C | 4 | A | D | 9 | 0 | 0 | E | F | 5 | D | 7 | E | 8 | 1 | F | 2 | F | D | 8 | 8 | C | 1 | B | B | E | 2 | D | 1 | 9 | A | D |
C | 9 | 8 | 9 | 0 | 2 | D | 2 | 3 | 4 | 9 | C | A | F | 9 | 0 | 2 | 3 | F | A | 8 | B | B | E | F | 0 | D | E | 2 | C | C | E |
5 | C | C | A | 1 | 1 | 2 | 2 | F | C | 9 | A | 9 | B | C | 4 | 0 | E | 4 | A | 8 | 9 | F | C | 1 | 4 | E | 3 | 5 | D | A | D |
A | 6 | E | B | B | D | F | 3 | 0 | 8 | B | 7 | 9 | 8 | A | C | 1 | F | F | C | F | 9 | C | 9 | 0 | 2 | D | F | 5 | 9 | D | F |
9 | 8 | D | F | D | 9 | F | F | 3 | A | 8 | A | F | 1 | F | F | C | C | F | B | 9 | F | B | B | D | B | C | 3 | 3 | F | B | B |
9 | D | 8 | 7 | 0 | 9 | E | 1 | 1 | A | D | 8 | F | 0 | 1 | 3 | F | F | E | D | B | D | F | 8 | 0 | 0 | C | 2 | 3 | B | F | A |
7 | D | F | 9 | C | E | 0 | D | 1 | C | A | 9 | A | B | 2 | 4 | 0 | 2 | D | 8 | 6 | E | 9 | F | 0 | E | 2 | 0 | F | E | 0 | 8 |
C | B | A | 9 | 9 | 8 | B | E | E | 9 | B | 9 | 8 | D | 3 | D | B | 0 | 1 | D | A | B | 9 | B | A | E | 4 | 4 | 6 | 9 | F | 0 |
A | 8 | E | 7 | 0 | 2 | 1 | D | C | 7 | D | 8 | C | 2 | A | B | E | 5 | 0 | A | 8 | F | E | A | B | F | 1 | 3 | 4 | 7 | D | 0 |
9 | B | 9 | E | B | 2 | A | E | E | 6 | A | B | E | B | E | E | 1 | 3 | 5 | 9 | 6 | A | 0 | B | B | E | 0 | 0 | 5 | A | 7 | E |
9 | A | 6 | 7 | 9 | 2 | 0 | 3 | F | 8 | 9 | 6 | B | 9 | C | 0 | D | 4 | 5 | B | C | 1 | A | 9 | 1 | B | 5 | 4 | 6 | C | F | 0 |
B | C | F | 0 | B | A | F | 1 | 1 | 6 | A | E | 7 | D | C | C | B | D | D | E | A | A | C | D | B | E | E | 0 | 3 | 8 | E | F |
4 | A | B | B | 2 | 1 | B | 2 | D | C | 5 | 8 | E | C | C | E | 3 | 2 | 1 | 6 | 7 | B | D | D | 2 | E | 3 | 5 | 0 | 9 | E | 9 |
B | 6 | 8 | A | A | 0 | 3 | F | F | 8 | 5 | C | B | 9 | A | B | F | 0 | 3 | C | 6 | A | 8 | C | B | C | E | 1 | 1 | E | E | A |
A | D | A | 6 | B | 1 | C | B | 1 | 5 | B | 7 | F | 1 | E | C | 0 | 4 | 6 | A | C | 8 | A | 9 | F | F | 1 | 4 | 3 | A | D | 0 |
A | 9 | D | B | 1 | A | C | 2 | 1 | C | 8 | 8 | A | 8 | C | F | B | D | F | 8 | F | 1 | B | 0 | D | C | 0 | 3 | 5 | 7 | B | E |
8 | 5 | 8 | E | E | B | E | B | E | 4 | 9 | D | 7 | C | C | 3 | C | 0 | 1 | 9 | 8 | 9 | A | E | E | B | 4 | 4 | F | C | 9 | E |
A | D | D | F | F | B | A | B | C | 8 | 9 | D | B | C | 2 | 2 | 0 | 2 | 5 | D | E | 7 | C | C | E | 1 | C | 1 | 6 | 8 | 7 | 8 |
B | 5 | B | F | D | 2 | 0 | E | 0 | A | D | 7 | B | A | E | 1 | E | E | 5 | 9 | A | F | A | 9 | 0 | C | 1 | 1 | E | 7 | D | B |
C | E | 7 | B | F | B | E | 3 | 2 | 5 | D | 8 | 9 | 9 | A | A | D | 1 | 1 | D | F | A | E | C | D | D | 1 | 4 | 4 | 7 | 0 | A |
7 | B | 8 | C | B | 1 | E | F | 3 | 4 | 8 | 0 | B | A | 1 | A | 3 | 5 | 4 | B | 6 | C | B | F | 3 | F | 4 | 4 | 6 | B | A | 1 |
5 | 6 | C | E | B | E | D | F | D | A | D | C | 0 | C | C | 3 | 2 | 1 | D | 9 | A | C | 9 | C | E | 1 | 0 | 4 | 4 | D | D | B |
6 | A | E | 9 | B | C | 1 | 3 | 2 | A | C | F | 7 | F | F | 0 | 2 | 0 | C | B | 7 | 9 | 0 | F | 2 | B | 0 | 0 | 1 | F | F | F |
A | F | C | B | E | E | A | 3 | 4 | 9 | B | B | A | B | 1 | C | 2 | 1 | 0 | A | C | 7 | C | D | B | E | C | 0 | 1 | D | C | B |
9 | F | 9 | E | 9 | E | F | 0 | D | 3 | B | C | D | 1 | C | 1 | E | 2 | F | A | B | E | D | A | F | 2 | 0 | D | 6 | A | D | E |
9 | D | D | 9 | F | D | 1 | 2 | 1 | 5 | 9 | 8 | A | D | A | 0 | F | 3 | 1 | C | C | B | 7 | D | B | 2 | 4 | 7 | 0 | E | F | 1 |
5 | 7 | 0 | 9 | 1 | B | C | E | C | 4 | 7 | F | 8 | C | D | F | 1 | F | 1 | D | 7 | E | 8 | E | C | F | D | 3 | 0 | 6 | 0 | A |
No comments:
Post a Comment