- line 1: panes / tabs, panes will split the new tab as needed and tabs make a new tab for each host.
- line 2: command to enter befotre the hostname in each host
- line 3 -> X: The number of hosts you want to connect to.
panes
ssh -i key.pem ec2-user@
hostname1
hostname2
hostname3
hostname4
hostname5
hostname6
#!/usr/bin/env python3.7
import iterm2
import math
ompirt os
async def main(connection):
#load server list
input = []
filePath = os.path.expanduser("~")+'/servers/new_servers'
print (filePath)
with open(filePath) as file:
input = file.read().splitlines()
# get a list of server
servers = input
command = input[1]
open_type = input[0]
servers.pop(0)
servers.pop(0)
app = await iterm2.async_get_app(connection)
window = app.current_terminal_window
print (open_type)
if window is not None:
if open_type == 'panes':
tab = await window.async_create_tab(index=0)
sessions = []
server_count = len(servers)
#Add the firt Session the the session list for clarity and ease of use
sessions.append(tab.sessions[0])
for i in range(2):
print("split Vertical")
sessions.append(await sessions[i].async_split_pane(vertical=True))
if server_count > 3:
for i in range ( (math.ceil(server_count / 3)-1)*3 ):
if (i+3) < server_count:
print("Split Horizontal")
sessions.append(await sessions[i].async_split_pane(vertical=False))
counter = 0;
for server in servers:
await sessions[counter].async_set_name("Server " + str(counter))
await sessions[counter].async_send_text(command + server)
profile = await sessions[counter].async_get_profile()
await profile.async_set_badge_text("Server " + str(counter))
counter+= 1
elif open_type == 'tabs':
tabs = []
for server in servers:
tabs.append(await window.async_create_tab())
await tabs[-1].sessions[0].async_send_text(command + server)
profile = await tabs[-1].sessions[0].async_get_profile()
await profile.async_set_badge_text("Server " + str(counter))
else:
# You can view this message in the script console.
print("No current window")
iterm2.run_until_complete(main)