User Tools

Site Tools


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 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/ &


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.

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: 2023/03/09 22:35 by