time error in a script
Posted: Mon Jan 01, 2018 10:06 am
This one has me mystified, all I can think of is the relatively slow speed of the Pi B is causing some kind of race condition. It's a simple script that is supposed to run and annotate a picture from the Pi's camera and upload it to a web site but only between certain times. It works fine except that occasionally it runs when it shouldn't. Some days it takes a single picture at 00:00 and uploads it when it should only work after 7am and before 9pm.
The script (with log in information obscured):
Anyone any ideas why the extra picture is produced? It is always at 00:00, as though it somehow slips through the time check.
The script (with log in information obscured):
Code: Select all
#!/bin/bash
## outer loop runs forever
while true;
do
## inner loop restricts operation to after 07:00 and before 21:00
while [ $(date +"%k") -gt 7 -a $(date +"%k") -lt 21 ];
do
echo taking picture
raspistill -q 20 -t 500 -n -o /home/pi/webcam/raw_camera.jpg -w 320 -h 240
nowday=$(date +"%A,")
nowdate=$(date +"%d-%b-%Y")
nowtime=$(date +"%H:%M")
echo annotating footer image
convert /home/pi/webcam/banner_320x30.jpg \
-fill '#0008' -draw 'roundrectangle 5,5,315,25,20,20' \
-fill white -annotate +20+20 '© dyfi.com' \
-annotate +95+20 "$nowday" \
-annotate +165+20 "$nowdate" \
-annotate +270+20 "$nowtime" \
/home/pi/webcam/footer_320x30.jpg
echo combining camera and footer images
convert -append /home/pi/webcam/raw_camera.jpg /home/pi/webcam/footer_320x30.jpg /home/pi/webcam/webcam_image.jpg
echo uploading image
ncftpput -u xxxxxxxxx -p xxxxxxxxxxxxxxxx xxxxxxxxxx.com /xxxxxxxxx/xxxxxxxxx /home/pi/webcam/webcam_image.jpg
echo waiting 30 seconds
sleep 30
done
done
exit 0