Skip to content

Instantly share code, notes, and snippets.

@marshyski
Last active August 29, 2015 14:11
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 marshyski/18c81ae8838859df75e7 to your computer and use it in GitHub Desktop.
Save marshyski/18c81ae8838859df75e7 to your computer and use it in GitHub Desktop.
Fabric checking for port 22 socket connection
from fabric.api import sudo, env, put
import configuration as config
import socket, time
env.hosts = open('hosts_file', 'r').readline().rstrip()
env.user = config.USERNAME
env.port = '22'
env.key_filename = config.KEY_FILE
env.warn_only = True
s = socket.socket()
while True:
try:
s.connect((env.hosts, 22))
break
except Exception:
time.sleep(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment