hack のためのネタ帳, etc,,,

状況

なぜか ssh の接続が安定せず、不定期に接続が切れる。
手動で再接続と byobu の reattach するのは面倒なので、
自動で再接続して byobu も自動 reattach して欲しい。

しかし、
ssh $HOST byobu
としてみると以下のように表示されて byobu の起動に失敗する。
Warning: untrusted X11 forwarding setup failed: xauth key data not generated
/usr/bin/byobu: 66: export: ではありません: bad variable name

解決方法

autossh byobu attach」でググったら以下のページを見つけた。
どうも、ssh に以下のオプションを追加しておくのがポイントらしい。
     -t      Force pseudo-terminal allocation.  This can be used to execute
             arbitrary screen-based programs on a remote machine, which can be
             very useful, e.g. when implementing menu services.  Multiple -t
             options force tty allocation, even if ssh has no local tty.

以下のようにすると ssh から直接 byobu を起動出来た。
ssh $HOST -t byobu

という事で、以下のようにすることで ssh から直接 byobu を起動し自動で reattach する事が出来た。
ssh $HOST -t "byobu -Rxr byobu"
因みに、うちの byobu は backend が screen なので -Rxr は以下の通り。
-r [session]  Reattach to a detached screen process.
-R            Reattach if possible, otherwise start a new session.
-x            Attach to a not detached screen. (Multi display mode).

通常の環境なら -r [session] はなくてもよいのだが、うちの環境では、byobu 以外のセッション名を付けた screen process を background で別にもう一つ走らせているので、 対話用のセッションと分けるためにこれが必要。

あとは、ssh を autossh に変更して、公開鍵認証と ssh-agent 使えば、切断時に自動再接続と自動 reattach される。

コメントをかく


「http://」を含む投稿は禁止されています。

利用規約をご確認のうえご記入下さい

Wiki内検索

フリーエリア

管理人/副管理人のみ編集できます