Skip to content

Instantly share code, notes, and snippets.

@hnakamur
Created July 13, 2016 03:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save hnakamur/9c9b5f4ae1322ce4ffb70a76aab8cc02 to your computer and use it in GitHub Desktop.
tmuxで複数のLXDコンテナ用にペインを開いて同時にキー入力するスクリプト
#!/bin/bash
# copied from http://tech.naviplus.co.jp/2014/01/09/tmux%E3%81%A7%E8%A4%87%E6%95%B0%E3%82%B5%E3%83%BC%E3%83%90%E3%81%AE%E5%90%8C%E6%99%82%E3%82%AA%E3%83%9A%E3%83%AC%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3/
# and modified for LXD
if [ -n "$SESSION_NAME" ];then
session=$SESSION_NAME
else
session=multi-lxc-`date +%s`
fi
window=multi-lxc
### tmuxのセッションを作成
tmux new-session -d -n $window -s $session
### 各コンテナでlxc exec $host --/bin/bash
# 最初の1台はlxc execするだけ
tmux send-keys "lxc exec $1 -- /bin/bash" C-m
shift
# 残りはpaneを作成してからlxc exec
for i in $*;do
tmux split-window
tmux select-layout tiled
tmux send-keys "lxc exec $i -- /bin/bash" C-m
done
### 最初のpaneを選択状態にする
tmux select-pane -t 0
### paneの同期モードを設定
tmux set-window-option synchronize-panes on
### セッションにアタッチ
tmux attach-session -t $session
@hnakamur
Copy link
Author

使い方: ~/bin/multi_lxc という名前で保存して chmod +x ~/bin/multi_lxc で実行権をつけてPATHに ~/bin を追加しておきます。

例えばubuntu1とubuntu2というコンテナにつなぐには

multi_lxc ubuntu{1,2}

のように実行します。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment