Skip to content

Instantly share code, notes, and snippets.

@Dreamzilla Dreamzilla/importer.py
Last active May 15, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.