运行 Ubuntu 19.10
我已经审查过有关 crontab 脚本的 wiki但我仍然不确定为什么我的没有启动。我想要运行的 bash 脚本如下:
#!/bin/bash
now_hour=$(date "+%H")
while ((now_hour < 21))
do
start_time=$(date "+%d.%m.%Y-%H:%M:%S")
status=$(ping -q -w 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` > /dev/null && echo ok || echo error)
if [ "$status" == "ok" ]
then
timeout 30m vlc -vvv http://10.0.0.113:8000/stream.mjpg --sout="#std{acces=file,mux=ogg,dst=/home/whsrobotics/KestrelCam/Recordings/Kestrel_Box:$start_time.mp4}"
echo "$start_time,recording_started" | tee -a "/home/whsrobotics/KestrelCam/log.txt"
else
echo "$start_time,network_problem" | tee -a "/home/whsrobotics/KestrelCam/log.txt"
sleep 5m
fi
now_hour=$(date "+%H")
done
我的 crontab 文件在这里:
# crontab -e
SHELL=/bin/bash
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
# start the Kestrel Camera recording at 5:00 am every day (will run to at least 9:00 pm)
00 05 * * * /home/whsrobotics/KestrelCam/all_day
在终端中手动启动时,脚本可以按预期工作,但从 cron 启动时则不行。我怀疑可能是 PATH 的问题,但我不知道该如何解决。欢迎提出任何建议。