rpirena/rpirena.cgi

82 lines
1.6 KiB
Text
Raw Permalink Normal View History

#! /bin/bash
# -*- sh -*-
cat <<EOT
Content-type: text/html
<html>
<head>
<meta http-equiv="refresh" content="60"/>
</head>
<body>
EOT
exec 2>&1
cd /home/pi/stephan/rpirena || exit
echo "$REMOTE_ADDR $HTTP_USER_AGENT" >>rpirena-cgi.log
fn=$(ls -rt1 2*.EIH | tail -1)
fn2=$(ls -rt1 2*.EI | tail -1)
if [ "$fn" -nt "$fn-cgi.png" ] && dotlockfile -r 0 rpirena-cgi.lock
then
date +"Plot $fn %Y-%m-%d %H:%M:%S" >>rpirena-cgi.log
cat <<EOT | gnuplot
set title "RPiRENA $fn"
set style data histeps
set log y
set yrange [0.9:*]
set xra [-100:1100]
set grid lt 9
set timestamp
set term png
set out "$fn-cgi.png-new"
plot "$fn" u 1:2 tit "ch 0", "" u 1:3 tit "ch 1", "" u 1:4 tit "ch 2", "" u 1:5 tit "ch 3"
unset out
EOT
mv $fn-cgi.png-new $fn-cgi.png
if [ "$fn2" -nt "$fn2-cgi.png" ]
then
date +"Plot $fn2 %Y-%m-%d %H:%M:%S" >>rpirena-cgi.log
cat <<EOT | gnuplot
set title "RPiRENA $fn2"
set yrange [-50:500]
set xrange [-50:700]
set grid lt 9
set timestamp
set pointsize 0.5
set term png
set out "$fn2-cgi.png-new"
plot "<awk '/^E/&&\$15<20*mV{print \$12/mV, \$15/mV}' mV=14000 $fn2" tit "Ch 3" w p pt 7 lt 2, \
"<awk '/^E/&&\$12<20*mV{print \$12/mV, \$15/mV}' mV=14000 $fn2" tit "Ch 2" w p pt 7 lt 6, \
"<awk '/^E/&&\$12>20*mV&&\$15>20*mV{print \$12/mV, \$15/mV}' mV=14000 $fn2" tit "Ch 2&3" w p pt 7 lt 1
unset out
EOT
mv $fn2-cgi.png-new $fn2-cgi.png
fi
rm -f rpirena-cgi.lock
fi
cat <<EOT
<img src="/stephan/rpirena/$fn2-cgi.png"/>
<img src="/stephan/rpirena/$fn-cgi.png"/>
<p/>Older Spectra:
<ul>
EOT
for ofn in *-cgi.png
do
echo "<li> <a href="/stephan/rpirena/$ofn">$ofn</a>"
done
cat <<EOT
</ul>
</body>
</html>
EOT