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 f...@example.org -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;%n@%m: autossh -t $* 'screen -RdU'\a" autossh -x -t "$@" 'screen -RdU' } asc stands for "autossh + screen" I.e. I just call "asc f...@server.example.org" 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 | a...@deuxchevaux.org (Mail) X See http://www.nonhtmlmail.org/campaign.html | a...@noone.org (Mail+Jabber) / \ I love long mails: http://email.is-not-s.ms/ | http://abe.noone.org/ (Web) _______________________________________________ screen-users mailing list screen-users@gnu.org https://lists.gnu.org/mailman/listinfo/screen-users