SSH "tmux a || tmux"は時々動作しますか?

SSH

このコマンドは常に機能します(shまたはbashを使用)。

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

これらの方法は約半分ほど失敗します。

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

server exited unexpectedlytmuxまたはまたはでエラーが発生しましたlost server。 (テスト中にtmuxセッションが開いていないため、常に両方のコマンドを実行しました。)

なぜ彼らは失敗し、時々失敗しますが、必ずしもそうではありませんか?

ベストアンサー1

私は答えを見つけたと思います:

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接続を試みるだけでなく、tmuxサーバーも起動します(失敗して終了し始めます)。
  • このtmuxコマンドは新しいセッションを作成しようとします。場合によっては、サーバープロセスがtmux aまだ存在し、そのサーバーと通信することがあります。
  • 最後に、サーバープロセスが終了し、メッセージtmuxで失敗します。server exited unexpectedly

おすすめ記事