How to Run a Long Running Process Using the Screen command via SSH

Here is a step-by-step guide on how to run a long-running process using the screen command via SSH:

  1. SSH into your server

    Open your terminal and SSH into your server using the following command:

    ssh username@your_server_ip
    

    Replace username with your actual username and your_server_ip with the IP address of your server.

  2. Install the Screen utility

    If the screen utility is not installed on your server, you can install it using the following command:

    For Ubuntu/Debian:

    sudo apt-get install screen
    

    For CentOS:

    sudo yum install screen
    
  3. Start a new Screen session

    You can start a new screen session using the following command:

    screen -S session_name
    

    Replace session_name with a name for your session. This will be useful for identifying the session later.

  4. Run your Python script

    Now, you can run your Python script using the following command:

    python your_script.py
    

    Replace your_script.py with the name of your Python script.

  5. Detach from the Screen session

    You can detach from the screen session and let your script run in the background using the following key combination:

    Ctrl + A, then press D
    

    This will detach your screen session but will keep your script running in the background.

  6. Reattach to the Screen session

    You can reattach to your screen session to check the progress of your script using the following command:

    screen -r session_name
    

    Replace session_name with 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.


Posted

in

by

Tags:

Comments

Leave a Reply