Python Forum
How do I make RPi run script on startup?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I make RPi run script on startup?
#1
I have a RPi2 running a script indefinitely with a scheduler.  But when the power goes out, which is often, the RPi2 reboots and I have to type "python scriptname.py" again to get it back up and running.

How do I make my RPi2 always run that script again after every reboot?
Reply
#2
You can add it to your bashrc file at the bottom to start at your login

edit your script and add the shebang line
Quote:
#!/usr/bin/env python


then make it executable
chmod a+x scriptname.py
then verify it runs as
./scriptname.py
then put that at the bottom of the file .bashrc
Recommended Tutorials:
Reply
#3
#Mars personal mods
Ok I need to create a tmux session and then run 2 scripts. Would this work?

#FIRST:run create tmux session
#SECOND: run reconnect.py to reconnect serialbt on rpi to bt relay board
#THIRD: run tsrb430.py to restart scheduler indefinitely

echo Running at boot...
sudo tmux new -s tsrb430
python /Documents/python/reconnectbt2tsrb.py
python /Documents/python/tsrb430.py
Reply
#4
I'm sorry, but would that code be OK?

I'm afraid of adding it and then getting my RPi stuck in some infinite loop or something.

I tried doing:
chmod a+x scriptname.py but I got this:

chmod a+x reconnect.py
chmod: changing permissions of ‘reconnect.py’: Operation not permitted
Reply
#5
In order to run chmod you have to be root.

sudo chmod +x reconnect.py
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#6
Thx! That did it!

Do you know if I can include that tmux new -s sessionName in the .bashrc? It wont freeze up my rpi? :-)
Reply
#7
You can. Start the tmux session, run what you want. Until you connect to the session the terminal will be free to use it.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Make entire script run again every 45 mo NDillard 0 317 Jan-23-2024, 09:40 PM
Last Post: NDillard
  Trying to make a board with turtle, nothing happens when running script Quascia 3 657 Nov-01-2023, 03:11 PM
Last Post: deanhystad
  Using Autostart to run a GUI program at startup. Rpi Edward_ 1 621 Oct-28-2023, 03:19 PM
Last Post: SpongeB0B
  Make console show after script was built with Pyinstaller --NOCONSOLE? H84Gabor 0 1,208 May-05-2022, 12:32 PM
Last Post: H84Gabor
  Make my py script work only on 1 compter tomtom 14 3,823 Feb-20-2022, 06:19 PM
Last Post: DPaul
  how to startup canbus interface on pi korenron 2 2,217 Oct-24-2021, 09:51 PM
Last Post: DeaD_EyE
  pexpect startup help korenron 2 3,479 Apr-27-2021, 07:23 AM
Last Post: korenron
  Error when running script on startup in Linux NoahTheNerd 0 1,953 Mar-07-2021, 04:54 PM
Last Post: NoahTheNerd
  Run script on startup in Debian with systemd? MrGlasspoole 5 3,642 Jul-12-2020, 11:48 AM
Last Post: MrGlasspoole
  Make the script read from any directory falahfakhri 2 2,159 Jun-15-2020, 02:18 PM
Last Post: falahfakhri

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020