Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I keep a python script on a remote server running after closing out of SSH?

I've coded a stock trading bot in Python3. I have it hosted on a server (Ubuntu 18.10) that I use iTerm to SSH into. Wondering how to keep the script actively running so that when I exit out of my session it won't kill the active process.

Basically, I want to SSH into my server, start the script then close out and come back into it when the days over to stop the process.

like image 652
David D Avatar asked Dec 31 '25 00:12

David D


1 Answers

You can use screen

sudo apt-get install screen

screen 

./run-my-script

Ctrl-A then D to get out of your screen

From there you will be able to close out your ssh terminal. Come back later and run

screen -ls

screen -r $screen_running

The screen running is usually the first 5 digits you see after you've listed all the screens. You can see if you're script is still running or if you've added logging you can see where in the process you are.

like image 62
Walter Schweitzer Avatar answered Jan 02 '26 13:01

Walter Schweitzer