Issue
I need to download some satellite images from sentinel2 via python script. I have already tested locally on a small amount of files and the script works correctly. Now I should run this script on an ssh session. My question is, how do I leave the script running (downloading) even if I close the ssh connection? Is it sufficient to launch the script in background (python3 main.py &
) ?
Solution
There are many tools for jobs like this: for example check this thread.
You can start with screen
.
$ screen # initiates a screen session
In the screen session, do:
$ python my_scripts.py
When the script is running, you can detach from the screen session with Ctrl-A
+D
.
The script will run in "background" and you can leave your current ssh session.
For batch downloads, you can shoot-up multiple screen sessions. You could assign a name for each screen when you initiate the session. In this way you can run multiple scripts, one in each session.
To check opened sessions:
$ screen -ls
There are screens on:
96185.pts-5.xxxxx-xxxx-xxx-xx (2022年07月01日 17时39分06秒) (Detached)
95231.pts-5.xxxxx-xxxx-xxx-xx (2022年07月01日 17时20分40秒) (Detached)
And to reattach to a specific session:
$ screen -r 96185
But before you do all of that, you might want to check there're enough resource (disk space, bandwidth, etc.).
Answered By - Ruiyu Ray Wang Answer Checked By - Marie Seifert (WPSolving Admin)