User Tools

Site Tools


run_program_at_boot

Run Program at Boot



You can set the Pi to run a program when the unit starts, this is quite often the case if you have a Pi running a task that needs to start if the unit is rebooted (by user or power outage etc).

I am running a Python script that displays the current IP Address on a 2 line LCD, I want this to run when the Pi boots (or reboots). The program is called UMD004.py and is located in the /home/pi/Python directory.


We can use the .bashrc file to run a program at boot:

  Ensure you are in the /home/pi folder and from the command line run:
  
  sudo nano .bashrc



At the end of the file add a line to run the Python script:

  sudo python /home/pi/Python/UMD004.py &



Note:

The & is important if your program does not end (say its a looping program) the & tells raspbian not to wait for the program to terminate before continuing.


Warning!!!
This method means that the script will run on each login. So if after boot, a user logs in via an SSH session, the script will run again. This will cause issues, if this is a problem, try the Cron method here.

run_program_at_boot.txt · Last modified: 2017/02/28 18:00 (external edit)