Last active
June 3, 2018 18:41
-
-
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
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
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