Skip to content

Instantly share code, notes, and snippets.

@alex-hofsteede
Last active December 6, 2016 23:20
Show Gist options
  • Save alex-hofsteede/0017a3e95a7e423a639b to your computer and use it in GitHub Desktop.
Save alex-hofsteede/0017a3e95a7e423a639b to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import subprocess
import sys
"""
Used in a tmux session, connects a synchronized interactive ssh session to all
hostnames read from stdin (1 per line). Preserves all ssh arguments.
Example usage:
tmux
./sshmux -i my-key.pem -o "User root" < hosts.txt
"""
for i, host in enumerate(sys.stdin):
args = " ".join(['"%s"' % arg for arg in sys.argv[1:]] + [host.strip()])
if i == 0:
subprocess.call(["tmux", "new-window", 'ssh %s' % args])
else:
pass
subprocess.call(["tmux", "split-window", "-h", 'ssh %s' % args])
subprocess.call(["tmux", "select-layout", "tiled"])
subprocess.call(["tmux", "select-pane", "-t", "0"])
subprocess.call(["tmux", "set-window-option", "synchronize-panes", "on"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment