Skip to content

Instantly share code, notes, and snippets.

@Dreamzilla
Last active May 15, 2017 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dreamzilla/be08dd9864438a43bf25d8442d6c8437 to your computer and use it in GitHub Desktop.
Save Dreamzilla/be08dd9864438a43bf25d8442d6c8437 to your computer and use it in GitHub Desktop.
Script that imports hosts from text file into Termius
#!/usr/bin/python
import sys
from subprocess import call
def make_call(host):
call = [
'termius', 'host', '-L',
host[0], '-a', host[1]
]
if len(host) >= 3:
call += ['-u', host[2]]
if len(host) == 4:
call += ['-P', host[3]]
return call
def main():
if len(sys.argv) != 2:
print('Please, provide the filename as an argument!\n')
return
filename = sys.argv[1]
delimiter = ','
hosts = []
with open(filename, 'r') as f:
for line in f:
hosts.append(line.strip().split(delimiter))
login_result = call(['termius', 'login'])
if login_result:
return
for host in hosts:
if not len(host):
continue
call(make_call(host))
call(['termius', 'pull'])
call(['termius', 'push'])
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment