Skip to content

Instantly share code, notes, and snippets.

@yosugi
Forked from nikushi/tmux-multi-ssh
Created June 21, 2016 05:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yosugi/089899d5099664d56846b143c750ca2e to your computer and use it in GitHub Desktop.
Save yosugi/089899d5099664d56846b143c750ca2e to your computer and use it in GitHub Desktop.
tmuxで複数にsshしてコマンドシンクするスクリプト by @mikeda
#!/bin/bash
#
# http://tech.naviplus.co.jp/2014/01/09/tmuxで複数サーバの同時オペレーション/
#
if [ -n "$SESSION_NAME" ];then
session=$SESSION_NAME
else
session=multi-ssh-`date +%s`
fi
window=multi-ssh
### tmuxのセッションを作成
tmux new-session -d -n $window -s $session
### 各ホストにsshログイン
# 最初の1台はsshするだけ
tmux send-keys "ssh $1" C-m
shift
# 残りはpaneを作成してからssh
for i in $*;do
tmux split-window
tmux select-layout tiled
tmux send-keys "ssh $i" 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