I installed octoprint to my raspberry pi earlier this year in order to control my 3d printers.

I've been able to make the pi control 2 printers at once using octoprint. Also I've added a second camera (USB) to view the second printer. I managed to find a way to start the second camera and edit octoprint to see the difference in the two.

My only problem is every time I start my raspberry pi up again I have to change to different a working directory:

cd ~/mjpg-streamer

then this to start the second camera:

./mjpg_streamer -i "./input_raspicam.so -fps 5" -o "./output_http.so -p 8090"&

I want to be able to write a script to start the camera on boot so I don't have to ssh to my raspberry, login, and send the commands every day. I've found a lot about writing boot scripts but nothing about changing the working directory inside it.

I've been using this to write start scripts (unsuccessfully):

sudo nano /etc/init.d/startsecondcamera

Make the startup script do the cd before running mjpg_streamer, just like you're doing manually:


cd /home/geilisa/mjpg-streamer
./mjpg_streamer -i "./input_raspicam.so -fps 5" -o "./output_http.so -p 8090"

This is assuming that your home directory is /home/geilisa.

You can't use ~ in the script since it's likely run by root. If running the utility as root is an issue, use sudo -u gelisia ./mjpg_streamer ... in the script to run it as user gelisia instead.

An alternative is to add a cron job that runs at boot:

@reboot cd /home/geilisa/mjpg-streamer && ./mjpg_streamer -i "./input_raspicam.so -fps 5" -o "./output_http.so -p 8090"

Add this in your crontab by using the command crontab -e. This will open an editor with your crontab (possibly an empty file). Add the above line, save, and exit.

Most cron's that I know of allows for using @reboot (and @hourly, @daily etc.) instead of the five job scheduling columns that usually goes before the actual command.

  • Thank you so much the cron job worked! I probably just messed up the script more, but that is okay. Thank you so much! – Geilisa Almodovar Sep 15 '17 at 16:49
  • @GeilisaAlmodovar Good! If this solves your issue, please consider accepting the answer. – Kusalananda Sep 15 '17 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.