Help with a startup script.


8 posts
by T800 » Mon Aug 05, 2013 8:50 pm
Can someone help me with some sort of startup script for when the Pi boots.

Once the Pi has started I SSH in and send these commands via terminal on my mac:

Code: Select all
mkdir /tmp/stream

cd /home/pi/mjpg-streamer/mjpg-streamer

LD_LIBRARY_PATH=./ ./mjpg_streamer -i "input_file.so -f /tmp/stream" -o "output_http.so -w ./www"


I then open another terminal and send:

Code: Select all
raspistill -w 1280 -h 720 -q 5 -o /tmp/stream/pic.jpg -tl 10 -t 10000000 -th 0:0:0 &



Can anyone help me?
Posts: 15
Joined: Fri Jul 12, 2013 7:59 am
by kghunt » Mon Aug 05, 2013 8:58 pm
First step is to put all your commands in an .sh file and make it executable with
Code: Select all
chmod a+x filename.sh


Run this script manually to make sure it has the desired output.
Code: Select all
./filename.sh


Then edit crontab
Code: Select all
crontab -e


And add this
Code: Select all
@reboot sh /pathtofile/filename.sh &

The ampersand at the end backgrounds the process so it doesn't hold up booting while the script runs.

There are other methods but this is the easiest to get started.
Posts: 360
Joined: Sun Mar 04, 2012 9:28 am
by T800 » Mon Aug 05, 2013 9:23 pm
Thanks for that I will give it a go.
Posts: 15
Joined: Fri Jul 12, 2013 7:59 am
by T800 » Thu Aug 08, 2013 3:03 pm
I did all that and it worked a treat. I now have a fully capable CCTV ip camera that starts up and streams on boot.

Thanks again.
Posts: 15
Joined: Fri Jul 12, 2013 7:59 am
by Joe Schmoe » Thu Aug 08, 2013 3:32 pm
I don't think you need the & in the crontab. I've never used @reboot myself, but you should never need an & in a crontab file entry.

Still, it may be a good idea, given that it can be scary when you put something in one of these startup scripts and it causes the boot process to hang (I'm thinking more of rc.local here).
Never answer the question you are asked. Rather, answer the question you wish you had been asked.

- Robert S. McNamara - quoted in "Fog of War" -
Posts: 2781
Joined: Sun Jan 15, 2012 1:11 pm
by kghunt » Thu Aug 08, 2013 6:30 pm
You are probably right. @reboot does work though. I have a python script that I run from cron every 12 hours. It posts information about my pi (load,local ip, public ip etc) into a google spreadsheet. I use at reboot to call it at boot too.
Posts: 360
Joined: Sun Mar 04, 2012 9:28 am
by T800 » Tue Aug 27, 2013 6:35 am
This has been working great for a while now with only one issue.

Code: Select all
raspistill -w 1280 -h 720 -q 20 -o /tmp/stream/pic.jpg -tl 10 -t 1000000000 -th 0:0:0 &


The time the camera is set to run for is 11 days (-t 1000000000) and after that I need to reboot the pi. If I set it one digit higher (115 days) it doesn't run. To get this fully auotmatic I need a higher run time for the camera or for the pi to reboot itself every week.

Is there a weekly reboot script I can run?
Posts: 15
Joined: Fri Jul 12, 2013 7:59 am
by rpdom » Tue Aug 27, 2013 7:10 am
T800 wrote:Is there a weekly reboot script I can run?


You could use the "@weekly" crontab option, which is the same as putting "0 0 * * 0", meaning "run this at 00:00 on day 0 (Sunday) of every week". It would probably be best if you put a line in the root crontab for this, so
Code: Select all
sudo -e crontab

and add a line like
Code: Select all
@weekly /sbin/shutdown -r now
User avatar
Posts: 3720
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK