Let's say I have this python script on my VPS:

# test.py
import time

while True:

If I log into my VPS using SSH and run this script, I can see tick... messages appearing in the console. But if I log out and log in again, everything is gone. I can see using htop that the python script is still running, just not printing anything into my new SSH session.

Is there any way I can recover the last SSH session, so I can see the results of my script again?

I tried the screen tool (screen -S test -> python test.py), but after re-connecting to SSH, when I try to go to my screen session (screen - S test) it only prints [screen is terminating].

  • 1
    Running screen -S test multiple times will result in multiple sessions, see screen -ls to list all sessions.
    – pLumo
    Feb 4, 2021 at 15:03
  • @pLumo He did not run screen -S test the second time, but screen - S test (space between minus and S). This command is incorrect and screen is immediately returning.
    – raj
    Feb 4, 2021 at 16:04
  • @raj Sorry, it was typo in my post. My bad. Actually I didn't put the space between - and S when writing to the terminal.
    – nanuqcz
    Feb 4, 2021 at 16:15
  • @nanuqcz However, the command with space actually makes the screen terminate right away :)
    – raj
    Feb 4, 2021 at 17:54

1 Answer 1


The command screen - S test is incorrect. If you want to re-attach to your detached screen session called "test", you should use the command

screen -R test
  • Thank you, that was it :-) I'll just summarize, how it is working for me now: Connect to SSH → screen -S testpython test.py → Re-connect to SSH → screen -r test → I can see the script output :-)
    – nanuqcz
    Feb 4, 2021 at 16:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.