-
-
Save chris2k20/418ffb894d38c2aa0ee6f6b8c8ccace8 to your computer and use it in GitHub Desktop.
Start tmux and ssh to multiple hosts with synchronized input
This file contains hidden or 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 | |
if [ -z "$1" ]; then | |
echo "please supply at least one server to connect to" >&2 | |
exit 1 | |
fi | |
target=multi-ssh-$$ | |
if [ -z "$TMUX" ]; then | |
tmux new-session -d -s "$target" | |
fi | |
if [ -n "$(type -p autossh 2> /dev/null)" ]; then | |
ssh="AUTOSSH_GATETIME=${AUTOSSH_GATETIME:-0} autossh" | |
else | |
ssh="ssh" | |
fi | |
tmux new-window -n "$target" "$ssh $1" | |
shift | |
for host in "$@"; do | |
tmux split-window -t ":$target" -h "$ssh $host" | |
tmux select-layout -t ":$target" tiled #> /dev/null | |
done | |
tmux select-pane -t ":$target" | |
tmux set-window-option -t ":$target" synchronize-panes on #>/dev/null | |
if [ -z "$TMUX" ]; then | |
tmux attach-session -d -t ":$target" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment