5

So, I put my Pi on a custom quadcopter. I have a program that will track an object with a cam and send out pulse widths to control my motors. Anyway, right now I have to ssh into my Pi to run my executable. I am using a WiFi dongle to connect with ssh, but that thing is sucking a lot of current, so I need to get rid of it. I would like it to run my makefile executable on power up, instead of having to ssh in and run it each time I want to fly. I already have the Pi auto-logging in. The makefile is compiled and ready to go with sudo ./MyProg. Any thoughts?

elixenide
  • 210
  • 1
  • 5
  • 9
nreich
  • 108
  • 1
  • 4

3 Answers3

6

Put your command into the /etc/rc.local file. You don't have to use sudo because this file is run by init at boot time.

If you encounter problems doing this, see:

If the program is persistent (i.e., keeps on ticking) be certain to background it. If it does not have such a feature built in, use & at the end of the line. If you do not do this, likely your boot will snag for a bit then init will kill the process.

gurcanozturk
  • 3,748
  • 1
  • 21
  • 17
1

You can just run sudo crontab -e and add the @reboot prefix to the command. For example if you wanted to run bash /home/pi/script.sh on boot, simply add @reboot bash /home/pi/script.sh to the end of your crontab file. Remember that crontab is user specific and may require sudo and a full path of execution.

Patrick Cook
  • 6,365
  • 8
  • 38
  • 63
jeffresc
  • 209
  • 1
  • 5
1

For starting programs at boot time, another solution is to use systemd. This has the advantage of starting and stopping the program as well as just start on boot. A sample video tutorial illustrating how to use systemd is available here:

https://www.youtube.com/watch?v=eEuViHanjKI

There are also many other resources available by searching on "systemd".

Kolban
  • 1,794
  • 2
  • 16
  • 28