[Gllug] Disconnected ssh sessions and pseudo-terminals

Lesley Binks lesleyb at pgcroft.net
Tue Oct 28 12:05:51 UTC 2008


On Tue, Oct 28, 2008 at 11:33:08AM +0000, Pancro wrote:
> > And hopelessly tried 'screen' to get to the orphan terminal :(
> >
> > Any ideas?
> 
> Screen is not useful after the processes you want to "protect" have
> started in the terminal.
> 
> If you start screen as soon as you ssh into your host and run your
> processes from there, you will be able to reattach to the session
> without problems. I do it routinely at work to have my mutt and irssi
> sessions always on an internal server and then I attach to my email
> and IRC from wherever I am, from home, from my laptop, when
> travelling, etc.
> 
> The commands I use the most are:
> 
> "screen" (obviously) to start a new session
> "screen -dr" to attach to a running session (detaching it from
> somewhere else if needed)
I usually use 'screen -rAaD <screen PID>'
'screen -ls' will list the screens you have running and the number at
the front of the response is the screen PID.

The handy thing is - once having issued the recovery command once for a
screen, if/when I lose the connection, all I have to type is '!scre'.
This exploits the history command and executes 'screen -raAD ..' for me.

> Ctrl-a followed by A to give a name to the window
> Ctrl-a followed by d to detach the session and keep my processes running
> Ctrl-a followed by c to create a new window within the current screen session
> Ctrl-a followed by p to move to the previous window in the screen session
> Ctrl-a followed by n to move to the next window in the screen session
> Ctrl-a followed by a to send ^A to the process (e.g. go to the
> beginning of the line in many cases)
Ctrl-a Ctrl-a will take you to the previously visited window or shell rather than
cycling through all of them to get to a specific one.  Typically I might
have a number of shells open and work between two at a time, needing the
third or fourth occasionally.

When you have a number of shells opened within a screen they tend to be
ordered and you can use Ctrl-a 0 to go to the first shell you opened,
Ctrl-a 1 to go to the second and so on. 

If you close a shell within a screen, say you have four open and close
shell 3 then the next shell created will take up that empty slot and
become shell 3.

I ssh in, and either reconnect my screen or raise a new one.  I then
raise new shells within that screen - typically one to show top, one for mutt and
any number thereafter for any work I am doing.

I am sshing in off a windoze box atm and find that if I leave the thing
running and showing top the ssh session stays open longer.  So if I need
to do something else I simply leave the top shell displaying.  I thank
<insert suitable deities here> for putty.

If you want to close the whole screen session down you have to exit each
shell you have started.
> 
> I'm a fairly basic screen user and the commands above do all I need,
> many more are available and documented in the usual places.
ditto :)

Regards

Lesley
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list