Skip to content

Instantly share code, notes, and snippets.

@tmessinis
Last active June 3, 2018 18:41
Show Gist options
  • Save tmessinis/b48975145a4ab08f7ea736cfd12791f8 to your computer and use it in GitHub Desktop.
Save tmessinis/b48975145a4ab08f7ea736cfd12791f8 to your computer and use it in GitHub Desktop.
Python script that launches tiled synced tmux panes on specified hosts via ssh
from getpass import getuser
from sys import argv
from subprocess import call
username = getuser()
hosts = []
def multi_ssh_connection(hostnames):
cmd = "tmux new-session 'ssh {0}@{1}' \; ".format(username, hostnames[0])
for idx in range(len(hostnames)):
if idx == 0:
continue
else:
cmd += "split-window 'ssh {0}@{1}' \; ".format(username, hostnames[idx])
cmd += "set-window-option synchronize-panes on \; select-layout tiled"
return cmd
if len(argv) == 1:
hosts = input('Enter hostnames to ssh into separated by spaces: ').split(' ')
call(multi_ssh_connection(hosts), shell=True)
else:
call(multi_ssh_connection(argv[1:]), shell=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment