sportingchiefs
Posts: 9
Joined: Thu May 01, 2014 3:16 am

Issues with crontab and Raspivid

Tue Sep 30, 2014 6:39 pm

Hello all,

I have been in the process of setting up a puppy cam so that my wife and I can monitor our new puppy while at work. I have used my raspberry pi (model B) with a WiFi usb adapter (http://www.amazon.com/gp/product/B003MT ... UTF8&psc=1) and the raspberry pi camera module with the latest version of Raspbian. I followed the tutorial here: http://www.slickstreamer.info/2013/06/u ... le-to.html to set everything up so that it sends a stream to my ustream.tv channel. I keep running into an issue when trying to use crontab to schedule raspivid to come on at 0715 and to stop at 1700. I have put the code that Marcus wrote in a shell script that looks just like this:

Code: Select all

raspivid -t 9999999 -vf -hf  -w 960 -h 540 -fps 25 -b 500000 -o - | ffmpeg -i - -vcodec copy -an -metadata title="Puppy Cam" -f flv Ustream RMTP Here/Key is here
When I run the shell script on it's own everything works great and runs for the time specified in the code (about 3 hours) but when I put it in crontab it runs for about 3 minutes before the stream freezes up. After this happens I'm no longer able to ssh into the pi and have to unplug the power and plug it back in before I can. This is what I have have in crontab -e:

Code: Select all

15 7 * * 1-5 sudo /home/pi/startvid.sh
00 17 * * 1-5 sudo killall raspivid
Just now (I'm at work) I went into the pi with ssh and changed the crontab so that it would run for an hour and commented out the killall command and it did the same thing. Any thoughts on what's going on? Thanks!

- Tyler

elatllat
Posts: 1337
Joined: Sat Dec 17, 2011 5:05 pm

Re: Issues with crontab and Raspivid

Wed Oct 01, 2014 2:25 am

0) use nice
1) Use the root crontab and remove sudo.
2) make the script non-blocking ( nohup & , screen, tmux)
3) don't assume PATH or anything else in the environment is set.
4) wrap it in a service (/etc/inint.d/)
5) add some logging (date>>, 1>>, 2>>, echo return=$?>>, printenv>>)
SBC with 32GB RAM: https://hardkernel.com

FAQ : https://raspberrypi.stackexchange.com

Unanswered: https://www.raspberrypi.org/forums/search.php?search_id=unanswered

Return to “Troubleshooting”