简体   繁体   中英

Set time in cronjob for camera

I've installed motion mmal on Raspberry Pi and its recording video whenever I run startmotion script:

 #!/bin/sh
 nohup /home/pi/mmal/motion -n -c /home/pi/mmal/motion-mmalcam.conf        1>/dev/null 2>&1 </dev/null &

However, Its making continuous video until I stop motion.

I want to make a video of 5 minute after every 10 minutes. I tried the timeout command:

 #!/bin/sh
 timeout 5m nohup /home/pi/mmal/motion -n -c /home/pi/mmal/motion-mmalcam.conf        1>/dev/null 2>&1 </dev/null &

I was able to run script after every 1 hour by using this code:

0 * * * * nohup /home/pi/mmal/motion -n -c /home/pi/mmal/motion-                   mmalcam.conf        1>/dev/null 2>&1 </dev/null &

5 * * * * pkill -9 motion

How can I run this script after every 10 minutes?

Did the timeout option work, though?..

Anyway, if you want to run the cron commands you listed every 10 minutes, then this should work:

*/10 * * * * nohup /home/pi/mmal/motion -n -c /home/pi/mmal/motion-mmalcam.conf 1>/dev/null 2>&1 </dev/null &

5-59/10 * * * * pkill -9 motion

You set the "step" after the / , default step is 1, and * is equivalent to "range" 0-59 for minutes. See https://stackoverflow.com/a/19204734/1375470 for a great explanation.

By the way, if timeout command works, it would look better (aesthetically) in cron, as a single command at */10 IMO.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM