Python Forum
Run python script in RPi2 from ssh session
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Run python script in RPi2 from ssh session
#1
If I run a python script on a RPi2 from an ssh session, that script stops once the ssh session is terminated.  How do I make that python script run in the RPi2 indefinitely and irrespective of what happens with the ssh session?  Just run it from the local pi user?  I don't have a monitor on my pi so is there a way to make it run as local from a remote computer?
Reply
#2
Just add an ampersand at the end of the command line. For example
$ python start_server.py
becomes
$ python start_server.py &
Reply
#3
Hi, thanks. Where does that line go exactly?

Currently I ssh into the pi, go to the python script's directory and type:

python myscriptname.py
So you're saying that if I type in the start_server.py line first, itll make my script run indefinitely and irrespective of ssh session state?

Thx again.
Reply
#4
Just add "&" at the end of that line. (Not sure if a space is necessarily; I always use it.) But yes, the script will continue running after you kill your ssh session. Let me know if that doesn't work, but I tested it right before making that post.

Also for a fancier solution consider read this. In the past, it was more trouble than it was worth for me but it's still pretty awesome.
Reply
#5
Hello!
Look at tmux. You can create a session, run some program in it and then detach from the session. Every time you login to a machine locally or remotely you can attach to this session by its name and see what is going on with the program/script. You can create "windows", panes and run what you want in every pane. 

Just the first from DuckDuckGo: Basic tmux Tutorial - Windows, Panes, and Sessions over SSH - Youtube.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#6
Thanks! Gr8 stuff! Im using tmux
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,009 Jun-29-2023, 11:57 AM
Last Post: gologica
  How to kill a bash script running as root from a python script? jc_lafleur 4 5,793 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur
  win32 API: Launch Application to RDP session from background process python script rangeshgupta 0 2,092 May-28-2020, 09:41 PM
Last Post: rangeshgupta
  crontab on RHEL7 not calling python script wrapped in shell script benthomson 1 2,254 May-28-2020, 05:27 PM
Last Post: micseydel
  Package python script which has different libraries as a single executable or script tej7gandhi 1 2,583 May-11-2019, 08:12 PM
Last Post: keames
  Powershell Session translation to Python; Session code seems to not work Maverick494 1 3,551 Jun-26-2018, 05:16 PM
Last Post: Maverick494
  How to run python script which has dependent python script in another folder? PrateekG 1 3,105 May-23-2018, 04:50 PM
Last Post: snippsat
  How to call one python script and use its output in another python script lravikumarvsp 3 32,288 May-16-2018, 02:08 AM
Last Post: lravikumarvsp
  different baviour in script vs shell session xiaoyisimonguo 0 1,964 May-10-2018, 01:03 AM
Last Post: xiaoyisimonguo
  Check Python version from inside script? Run Pythons script in v2 compatibility mode? pstein 2 9,790 Jul-07-2017, 08:59 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

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