Here is a step-by-step guide on how to run a long-running process using the
screen command via SSH:
SSH into your server
Open your terminal and SSH into your server using the following command:
usernamewith your actual username and
your_server_ipwith the IP address of your server.
Install the Screen utility
screenutility is not installed on your server, you can install it using the following command:
sudo apt-get install screen
sudo yum install screen
Start a new Screen session
You can start a new
screensession using the following command:
screen -S session_name
session_namewith a name for your session. This will be useful for identifying the session later.
Run your Python script
Now, you can run your Python script using the following command:
your_script.pywith the name of your Python script.
Detach from the Screen session
You can detach from the
screensession and let your script run in the background using the following key combination:
Ctrl + A, then press D
This will detach your
screensession but will keep your script running in the background.
Reattach to the Screen session
You can reattach to your
screensession to check the progress of your script using the following command:
screen -r session_name
session_namewith the name of your session.
This way, even if your SSH session gets disconnected, your script will keep running in the
screen session. You can always reattach to the
screen session to check the progress of your script.