[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Four questions about examples of GNU Screen use
From: |
Axel Beckert |
Subject: |
Re: Four questions about examples of GNU Screen use |
Date: |
Sun, 6 Mar 2016 02:19:39 +0100 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
Hi Lars,
On Sat, Mar 05, 2016 at 08:23:42PM +0200, Lars Noodén wrote:
> 1) Here screen(1) is launched.
>
> ssh -l fred server.example.org screen
ssh lacks a -t option in this example (and the next one). Screen needs
a (pseudo) terminal.
> Once a screen(1) session is running, it is possible to detach it and
> close the SSH connection without disturbing the background processes it
> may be running. Then the terminal session can be reattached in progress.
>
> ssh -l fred server.example.org "screen -x"
"screen -x" works, but is probably not what most people use as it
connects to a screen session in addition to existing clients which
often restricts one of the clients to a smaller terminal than
available for him.
I usually use "screen -dr" for that:
-d = detach an attached session
-r = reattach the session here
What I do is usually
ssh -l fred server.example.org screen -Rd
-R = reattach if a session exists or creates a new session if no
session exists.
That way you only need one command for both purposes listed above.
This is especially nice for making shell aliases or so.
> 2) Here ssh(1) is to assume that the connection is broken after 5
> seconds of not being able to reach the server and to exit.
>
> while ! ssh -t address@hidden -o 'ServerAliveInterval 5' \
> screen -d -RR; do true; done
There's a nice tool which does this a little bit more intelligent:
http://www.harding.motd.ca/autossh/
Combined with the above, I use it in a shell function like this:
asc () {
print -Pn "\e]0;address@hidden: autossh -t $* 'screen -RdU'\a"
autossh -x -t "$@" 'screen -RdU'
}
asc stands for "autossh + screen"
I.e. I just call "asc address@hidden" and I do get a screen
session, either an existing one or a fresh one. In production for like
5 years now on a daily base -- also helps to survive setting the
laptop to sleep and waking it up at a different location with a
differnt IP address.
(And yes, there's also mosh. But the above has also the advance that I
can add any port forwardings or other SSH options and they're used
upon every reinstantiation of the connection again.)
HTH.
Kind regards, Axel
--
/~\ Plain Text Ribbon Campaign | Axel Beckert
\ / Say No to HTML in E-Mail and News | address@hidden (Mail)
X See http://www.nonhtmlmail.org/campaign.html | address@hidden (Mail+Jabber)
/ \ I love long mails: http://email.is-not-s.ms/ | http://abe.noone.org/ (Web)