Skip to content

Instantly share code, notes, and snippets.

@bhenderson
Forked from dmytro/ssh-multi.sh
Last active September 10, 2018 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bhenderson/e76c43b2925b45eb85ae8c2843bade26 to your computer and use it in GitHub Desktop.
Save bhenderson/e76c43b2925b45eb85ae8c2843bade26 to your computer and use it in GitHub Desktop.
Start multiple synchronized SSH connections with Tmux
#!/bin/bash
# SSH into multiple hosts with each in their own tmux pane.
if [ "$#" -lt 1 ]; then
cat >&2 <<-EOM
Usage: $(basename $0) host1 [ host2 ... ] [ -- ssh options ]
EOM
exit 1
fi
hosts=()
for opt; do
case "$opt" in
--)
shift
break
;;
*)
hosts+=( "$opt" )
shift
;;
esac
done
host=${hosts[0]}
unset hosts[0]
for i in "${hosts[@]}"; do
tmux split-window -h ssh "$i" $@
done
tmux select-pane -t 0
tmux select-layout tiled
tmux set-window-option synchronize-panes on
exec ssh "$host" $@
@svenXY
Copy link

svenXY commented Sep 10, 2018

Hi, for me it failed to open all panes with the error message 'pane too small' on a decent monitor and 8 panes.

Searching for this revealed:
tmuxinator/tmuxinator#48 (comment)

which suggests to run 'tmux select-layout tiled' after each new pane is spawned and this indeed fixed the problem for me

@svenXY
Copy link

svenXY commented Sep 10, 2018

I pushed it a little bit further to the following:
https://gist.github.com/svenXY/2e8a7a8d42cc99ada7cf18bdfbaa5ea3

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