modifying a time lapse bash script for raspberry pi - crashes before 10 Am

480 Views Asked by At

I got a bash script online that uses the raspberry pi's camera module to take photos at a specified rate for a specified timeframe. I can't seem to run the script before 10 am because it can't add the timeframe to the time (in 24 hour) because it has a 0 in front of the number. I tried adding a # in front of the variable like some other posts said but the pi spits out a syntax error. I'm obviously new to bash.

Code:

#!/bin/sh

if [ ! -n "$3" ]
then
    echo ""
    echo "\033[1;31mUsage: tl <interval (in seconds)> <duration (in hours)> <duration (in minutes)>"
    echo ""
    echo "\033[1;32mExample: tl 10 5 30"
    echo "(Takes a picture every 10 seconds for the next 5 hours and 30 minutes)"
    echo "\033[0m"

elif  [ ! -d /mnt/usb/tl_storage/pics_$(date +%F) ]
then
    sudo mkdir -p /mnt/usb/tl_storage/pics_$(date +%F)
    interval=$(($1 * 1000))
    duration=$((($2 * 60 + $3) * 60000))
    hour_act=$(date +%H)
    minute_act=$(date +%M)
    hour_tmp=$(($hour_act + $2))
    minute_tmp=$(($minute_act + $3))
    if [ "$hour_tmp" -gt 24 ]
    then
        hour_then=$(($hour_tmp - 24))
    else
        hour_then=$hour_tmp
    fi
    if [ "$minute_tmp" -gt 60 ]
    then
        minute_then=$(($minute_tmp -60))
        hour_then=$((hour_then + 1))
    else
        minute_then=$minute_tmp
    fi
    echo "\033[1;31mTaking Pictures for timelapse in progress. Check back at $hour_then:$minute_then"
    echo "\033[0m"
    cd /mnt/usb/tl_storage/pics_$(date +%F)/
    sudo raspistill -o lapse_%04d.jpg -tl $interval -t $duration
    cd $HOME
else
    interval=$(($1 * 1000))
    duration=$((($2 * 60 + $3) * 60000))
    hour_act=$(date +%H)
    minute_act=$(date +%M)
    hour_tmp=$(($hour_act + $2))
    minute_tmp=$(($minute_act + $3))
    if [ "$hour_tmp" -gt 24 ]
    then
        hour_then=$(($hour_tmp - 24))
    else
        hour_then=$hour_tmp
    fi
    if [ "$minute_tmp" -gt 60 ]
    then
        minute_then=$(($minute_tmp -60))
        hour_then=$((hour_then + 1))
    else
        minute_then=$minute_tmp
    fi
    echo "\033[1;31mTaking Pictures for timelapse in progress. Check back at $hour_then:$minute_then"
    echo "\033[0m"
    cd /mnt/usb/tl_storage/pics_$(date +%F)/
    sudo raspistill -o lapse_%04d.jpg -tl $interval -t $duration
    cd $HOME
fi

Command:

tl 5 0 5 //every five sec for five min

error:

/bin/tl: 19: /bin/tl: arithmetic expression: expecting EOF: "09 + 0"
0

There are 0 best solutions below