How to recover a 'lost' screen session?
Try detaching it first with screen -d
. If that doesn't work, you can try, in increasing order of emphasis,
-d|-D [pid.tty.host]
does not start screen, but detaches the elsewhere running screen session. It has the
same effect as typing "C-a d" from screen's controlling terminal. -D is the equivalent
to the power detach key. If no session can be detached, this option is ignored. In
combination with the -r/-R option more powerful effects can be achieved:
-d -r Reattach a session and if necessary detach it first.
-d -R Reattach a session and if necessary detach or even create it first.
-d -RR Reattach a session and if necessary detach or create it. Use the first session if
more than one session is available.
-D -r Reattach a session. If necessary detach and logout remotely first.
-D -R Attach here and now. In detail this means: If a session is running, then reattach.
If necessary detach and logout remotely first. If it was not running create it and
notify the user. This is the author's favorite.
-D -RR Attach here and now. Whatever that means, just do it.
screen -r '1234.somescreensession'
There is a screen on:
1234.somescreensession (Attached)
There is no screen to be resumed matching 1234.somescreensession.
Here is a simple way to take back that screen session.
screen -D -r '1234.somescreensession'
I experienced the same problem after my ssh connection closed unexpectedly with the message Write Failed: broken pipe
while I had a screen session attached. However, I could not get my screen session to reattach using any of the commands above. Note that I use the following version:
~> screen --version
Screen version 4.00.03 (FAU) 23-Oct-06
Apparently, there was still an instance of sshd
running, which kept me from detaching and reattaching the session. After identifying the PID
of the appropriate instance of sshd
and kill
ing it I was able to reattach with screen -r
.
Just for information: You will definitely find more than one sshd
demon, one will correspond to your current login and another belonging to the stale screen
session (indeed, there could be multiple other sshd
s running belonging to multiple other screen
s).