我在网上有一个bash脚本,它使用raspberry pi的相机模块在指定的时间范围内以指定的速率拍照。我似乎无法在上午10点之前运行脚本,因为它无法将时间帧添加到时间(24小时),因为它在数字前面有一个0。我尝试在变量前面添加一个#,就像其他一些帖子所说,但是pi吐出了一个语法错误。我显然是bash的新手。
代码:
#!/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
命令:
tl 5 0 5 //every five sec for five min
错误:
/bin/tl: 19: /bin/tl: arithmetic expression: expecting EOF: "09 + 0"