sbaratheon
Posts: 81
Joined: Sun Sep 30, 2012 10:33 am

Is there anything wrong with this bash script (timelapse)?

Sun Jan 14, 2018 2:25 pm

I've written the following bash script to use the rpi's camera as a timelapse (i didn't use raspistill directly as you can't save the timestamp):

Code: Select all

# Note: This script runs at startup (listed in /etc/rc.local)
#!/bin/bash


MINUTES=720
SECONDS_TO_RUN=$((60 * MINUTES))
DELAY=25

while [ "$SECONDS" -lt "$SECONDS_TO_RUN" ]; do
	DATE=$(date +"%H_%M_%S")
	raspistill --nopreview  -o /home/pi/timelapse/$DATE.jpg
	sleep $DELAY
done

The script does appear to run but only for 5 - 6 hours after which it seems to stop taking photos. I know that the rpi has more than enough space to save the photos on so that shouldn't be an issue.

The only thing which comes to mind is the internal $seconds variable - does this exclude time during which the 'sleep' command is running?

Many thanks in advance

User avatar
DougieLawson
Posts: 32364
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Is there anything wrong with this bash script (timelapse)?

Sun Jan 14, 2018 2:32 pm

Where does the $SECONDS variable get set? Where does that variable get updated?
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

sbaratheon
Posts: 81
Joined: Sun Sep 30, 2012 10:33 am

Re: Is there anything wrong with this bash script (timelapse)?

Sun Jan 14, 2018 2:47 pm

DougieLawson wrote:
Sun Jan 14, 2018 2:32 pm
Where does the $SECONDS variable get set? Where does that variable get updated?
I was under the impression that $SECONDS was an internal variable (http://tldp.org/LDP/abs/html/internalvariables.html)

User avatar
DougieLawson
Posts: 32364
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Is there anything wrong with this bash script (timelapse)?

Sun Jan 14, 2018 2:58 pm

OK. I'm not sure why your loop terminates and you're dumping any stderr messages into /dev/null by running it from /etc/rc.local.

Did you know that raspistill has a built-in timelapse option? Use that and your only remaining problem is killing it when 720 minutes are over.

-tl, --timelapse : Timelapse mode. Takes a picture every <t>ms. %d == frame number (Try: -o img_%04d.jpg)
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

User avatar
rpdom
Posts: 12412
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK

Re: Is there anything wrong with this bash script (timelapse)?

Sun Jan 14, 2018 3:34 pm

sbaratheon wrote:
Sun Jan 14, 2018 2:47 pm
I was under the impression that $SECONDS was an internal variable (http://tldp.org/LDP/abs/html/internalvariables.html)
It is. But you might want to set it to zero at the start.

sbaratheon
Posts: 81
Joined: Sun Sep 30, 2012 10:33 am

Re: Is there anything wrong with this bash script (timelapse)?

Sun Jan 14, 2018 3:56 pm

DougieLawson wrote:
Sun Jan 14, 2018 2:58 pm
OK. I'm not sure why your loop terminates and you're dumping any stderr messages into /dev/null by running it from /etc/rc.local.

Did you know that raspistill has a built-in timelapse option? Use that and your only remaining problem is killing it when 720 minutes are over.

-tl, --timelapse : Timelapse mode. Takes a picture every <t>ms. %d == frame number (Try: -o img_%04d.jpg)
That command saves by the frame number. I need to record the timestamp in the image.

sbaratheon
Posts: 81
Joined: Sun Sep 30, 2012 10:33 am

Re: Is there anything wrong with this bash script (timelapse)?

Sun Jan 14, 2018 3:57 pm

rpdom wrote:
Sun Jan 14, 2018 3:34 pm
sbaratheon wrote:
Sun Jan 14, 2018 2:47 pm
I was under the impression that $SECONDS was an internal variable (http://tldp.org/LDP/abs/html/internalvariables.html)
It is. But you might want to set it to zero at the start.
I thought the variable recorded the number of seconds elapsed since the script started running (i.e. it's set at 0 when the script first runs)?

Return to “General programming discussion”

Who is online

Users browsing this forum: No registered users and 2 guests