#!/bin/bash

while :
do
sleep 7

LAST_CHANGE=`date -r "/tmp/band_lock" '+%s' 2>/dev/null`
NOW=`date '+%s'`

if [ $((NOW-LAST_CHANGE)) -lt 60 ]; then
    SONDE=`cat /tmp/band_lock`
    echo "BAND LOCKED for $SONDE" >> /tmp/sondelog
    continue
fi

BAND=`cat /tmp/band 2> /dev/null`
((BAND++))
((BAND %= 3))
echo $BAND > /tmp/band

BANDFILE="/var/www/html/spdxl/conf/sdrcfg$BAND.txt"

echo "CURRENT BAND: "$BAND
(
echo -e -n CURRENT BAND: $BAND " "
cat $BANDFILE | grep '^f\w*' | awk '{printf "%s ",$2}'
) >>/tmp/sondelog
cat $BANDFILE > /tmp/sdrcfg.txt

done
