CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/scripts/sshvm
Views: 791
#!/usr/bin/env python
from __future__ import print_function

import os, sys, time

n = sys.argv[1]
if '@' in n:
    user, host = n.split('@')
    user = user + '@'
else:
    user = ''
    host = n

def dot():
    sys.stdout.write('.'); sys.stdout.flush()

print("waiting for ip address", end=" ")
sys.stdout.flush()

while True:
    addr = os.popen('kvm_addresses.py %s'%host).read().strip()
    if addr:
        break
    dot()
    time.sleep(2)

print("\ntrying to ssh in:")

while True:
    t = time.time()
    s = "ssh -o StrictHostKeyChecking=no %s%s"%(user, addr)
    print(s)
    os.system(s)
    if time.time()-t > 3:
        break
    else:
        time.sleep(2)