Created
July 13, 2016 03:27
Star
You must be signed in to star a gist
tmuxで複数のLXDコンテナ用にペインを開いて同時にキー入力するスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
使い方:
~/bin/multi_lxc
という名前で保存してchmod +x ~/bin/multi_lxc
で実行権をつけてPATHに~/bin
を追加しておきます。例えばubuntu1とubuntu2というコンテナにつなぐには
のように実行します。