T800
Posts: 18
Joined: Fri Jul 12, 2013 7:59 am

Help with a startup script.

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?

kghunt
Posts: 383
Joined: Sun Mar 04, 2012 9:28 am

Re: Help with a startup script.

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.

T800
Posts: 18
Joined: Fri Jul 12, 2013 7:59 am

Re: Help with a startup script.

Mon Aug 05, 2013 9:23 pm

Thanks for that I will give it a go.

T800
Posts: 18
Joined: Fri Jul 12, 2013 7:59 am

Re: Help with a startup script.

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.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Help with a startup script.

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).
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

kghunt
Posts: 383
Joined: Sun Mar 04, 2012 9:28 am

Re: Help with a startup script.

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.

T800
Posts: 18
Joined: Fri Jul 12, 2013 7:59 am

Re: Help with a startup script.

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?

User avatar
rpdom
Posts: 11426
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK

Re: Help with a startup script.

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

Return to “Beginners”

Who is online

Users browsing this forum: rpdom and 49 guests