Created
October 31, 2012 03:46
-
-
Save dmytro/3984680 to your computer and use it in GitHub Desktop.
Start multiple synchronized SSH connections with Tmux
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 | |
# ssh-multi | |
# D.Kovalov | |
# Based on http://linuxpixies.blogspot.jp/2011/06/tmux-copy-mode-and-how-to-control.html | |
# a script to ssh multiple servers over multiple tmux panes | |
starttmux() { | |
if [ -z "$HOSTS" ]; then | |
echo -n "Please provide of list of hosts separated by spaces [ENTER]: " | |
read HOSTS | |
fi | |
local hosts=( $HOSTS ) | |
tmux new-window "ssh ${hosts[0]}" | |
unset hosts[0]; | |
for i in "${hosts[@]}"; do | |
tmux split-window -h "ssh $i" | |
tmux select-layout tiled > /dev/null | |
done | |
tmux select-pane -t 0 | |
tmux set-window-option synchronize-panes on > /dev/null | |
} | |
HOSTS=${HOSTS:=$*} | |
starttmux |
@greymd xpanes! - Thank you! I've been looking for exactly this off and on for two years.
#!/bin/bash
#tmux-ssh.sh
# Assume session is 0
tmux attach-session -t 0
WINDOW=$(tmux display-message -p "#I")
FIRST_ARG=""
for arg in $*; do
if [[ $arg != *"%"* ]]; then
if [[ $FIRST_ARG == "" ]]; then
FIRST_ARG=$arg
tmux send-keys "ssh $arg" Enter
else
tmux split-window "ssh $arg"
fi
tmux select-layout tiled
fi
done
tmux set-window-option synchronize-panes on
This is how my old co-worker accomplished this, figured I'd drop in this thread not as a replacement but an alternate option.
#!/usr/bin/env bash
instead of of hardcoded shebang
Thank you, sir. I found your code very useful for setting environments across multiple servers.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great little script! Especially this one:
tmux set-window-option synchronize-panes on > /dev/null
, it's something magic for me! I was using clusterssh before for the same feature, and never know tmux can do this!BTW: the script in original post works well with tmux 2.1 for me, on a Ubuntu 16.04 box with tmux installed by apt,
tmux -V
saystmux 2.1
.