2

This command works always (with sh or bash):

ssh -t HOST sh -c "tmux a 2>/dev/null || tmux"

These fail about half the time:

ssh -t HOST -- "tmux a 2>/dev/null || tmux"
ssh -t HOST "tmux a 2>/dev/null || tmux"

with an error from tmux, either server exited unexpectedly or lost server. (When testing there was no open tmux session so it always ran both commands.)

Why do they fail and only fail sometimes but not always?

1 Answer 1

1

I think I found the answer:

attach-session [-dErx] [-c working-directory] [-t target-session]
              (alias: attach)
        If no server is started, attach-session will attempt to start it; this will 
        fail unless sessions are created in the configuration file.
  • tmux a not only tries to attach but also starts a tmux server (which fails and starts to shut down).
  • the tmux command tries to create a new session. Sometimes the server process from tmux a is still there, so it talks to that server
  • finally the server process exits and tmux fails with the server exited unexpectedly message.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .