Skip to content

Instantly share code, notes, and snippets.

@lalyos
Last active January 22, 2021 06:44
Show Gist options
  • Save lalyos/dc2089e6ac87712fb463dab833a9543b to your computer and use it in GitHub Desktop.
Save lalyos/dc2089e6ac87712fb463dab833a9543b to your computer and use it in GitHub Desktop.
multi ssh with ansible or tmux

run a netcat server in one terminal/tmux pane and a client in a different one. Now all lines entered in the client side, will be "typed" into multiple ssh sessions.

ansible version

In this version all output comes back in a single stream:

nc -lk 12345 | while read line; do ansible -u centos -i hosts all -m raw -a "$line"; done

tmux version

This version separates outputs into separate tmux panes, but ssh connection has to set up beforehand.

nc -lk 12345 | while read line; do for i in {2..6}; do tmux send-keys -t $i "$line" ENTER; done; done

conect to it

connect from one terminal

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