[aklug] Re: resuming borked sessions

From: Szechuan Death <sdeath@sdeath.net>
Date: Mon Feb 24 2014 - 13:14:45 AKST

On 2/24/14, 9:45 AM, Everett Haimes wrote:
> For years I've been using a utility called screen to manage
> persistent SSH sessions. It's easy to use, you just SSH in to your
> host and type screen.
>
> If you disconnect from a screen session, all you have to do is SSH
> back in and type "screen -r" to reconnect or "screen -x" to reconnect
> to a currently attached session.

I second this, except that I much prefer tmux - written by the same
folks that brought you OpenBSD. I find that screen is only really
useful for its ability to interact with serial ports (which tmux doesn't
do, and which cu handles just fine anyway), so I don't miss it.

tmux has a nice clean syntax, a nice clean codebase (screen is a
nightmare), is similar in the ways that matter to screen, and different
where it counts. In particular, this bit is nice:

--- snip ---

     new-session [-AdDP] [-F format] [-n window-name] [-s session-name]
[-t target-session] [-x width] [-y height]
             [shell-command]
                   (alias: new)
             Create a new session with name session-name.

             The new session is attached to the current terminal unless
-d is given. window-name and shell-command are
             the name of and shell command to execute in the initial
window. If -d is used, -x and -y specify the size
             of the initial window (80 by 24 if not given).

             The -A flag makes new-session behave like attach-session if
session-name already exists; in the case, -D
             behaves like -d to attach-session.

             If -t is given, the new session is grouped with
target-session. This means they share the same set of win-
             dows - all windows from target-session are linked to the
new session and any subsequent new windows or win-
             dows being closed are applied to both sessions. The
current and previous window and any session options
             remain independent and either session may be killed without
affecting the other. Giving -n or
             shell-command are invalid if -t is used.

--- snip ---

So I've defined a bash function as follows:

ssht ()
{
    while true; do
        /usr/bin/ssh -t $1 tmux new-session -As $2;
        sleep 1;
    done
}

Used, basically, like this:

$ ssht host.blah session

It'll create that session if it doesn't exist, or attach to it if it
does. And when your network drops out, it'll reconnect as soon as it
figures it out and put you back in the same session without even blinking.

I find that my workflow is smoothed significantly by this. YMMV, of course.

-- 
""
-SD
---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Mon Feb 24 13:15:39 2014

This archive was generated by hypermail 2.1.8 : Mon Feb 24 2014 - 13:15:39 AKST