Skip to content

Instantly share code, notes, and snippets.

@johnko
Forked from dmytro/ssh-multi.sh
Last active July 28, 2022 15:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save johnko/a8481db6a83ec5ea2f37 to your computer and use it in GitHub Desktop.
Save johnko/a8481db6a83ec5ea2f37 to your computer and use it in GitHub Desktop.
a script to ssh multiple servers over multiple tmux panes
#!/bin/sh
# ssh-multi
# D.Kovalov
# Based on http://linuxpixies.blogspot.jp/2011/06/tmux-copy-mode-and-how-to-control.html
# Modified by johnko https://gist.github.com/johnko/a8481db6a83ec5ea2f37
# a script to ssh multiple servers over multiple tmux panes
starttmux() {
count=0
if [ -z "${1}" ]; then
echo -n "Please provide of list of hosts separated by spaces [ENTER]: "
read HOSTS
else
HOSTS=$*
fi
for i in ${HOSTS} ; do
count=$(( count + 1 ))
if [ ${count} -eq 1 ]; then
if tmux ls >/dev/null 2>/dev/null ; then
tmux new-window "ssh ${i}"
else
tmux new-session -d "ssh ${i}"
fi
else
tmux split-window -h "ssh ${i}"
tmux select-layout tiled >/dev/null
fi
done
tmux select-pane -t 0
tmux set-window-option synchronize-panes on >/dev/null
}
starttmux $*
tmux attach
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment