Page 1 of 1

Auto run python script when Raspberry booted up.

Posted: Sun Apr 22, 2018 4:23 pm
by lwhistler
What is the best way to run a python script when the computer is turned on? When I Googled it I came across some solutions including the one below.


Crontab

Code: Select all

@reboot /home/len/Desktop/3d.py


  • It works but it was way down the list of answers and only had 1 like.
  • It also was the simplest to implement.
  • Is there anything I should be aware of when I'm using the crontab @reboot method?

Re: Auto run python script when Raspberry booted up.

Posted: Sun Apr 22, 2018 7:00 pm
by alphanumeric
It's how I do it. I forget why I have the & at the end though? It's been a long time since I looked up how to do it.
run sudo crontab -e
add
@reboot python3 /home/pi/myfile.py &

Re: Auto run python script when Raspberry booted up.

Posted: Sun Apr 22, 2018 7:08 pm
by pcmanbob
When placing & at the end of a line like that it makes bash start program in the background, so you can continue to use the shell and do not have to wait until the script is finished.

But it is not required in cron because programs are already run in the background.

running a python program like that is fine if you do have any screen output from the program.

Re: Auto run python script when Raspberry booted up.

Posted: Sun Apr 22, 2018 7:23 pm
by alphanumeric
Great, thanks for that info. Was just looking to see if I had saved a link to where I first looked that up. The Pi's I'm dong that on run headless with no monitor, keyboard or mouse. And boot to command line. Info / output is shown on a Sense hat LED matrix