Last active
May 15, 2017 13:37
-
-
Save Dreamzilla/be08dd9864438a43bf25d8442d6c8437 to your computer and use it in GitHub Desktop.
Script that imports hosts from text file into Termius
This file contains 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
#!/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