Created
April 23, 2015 21:16
-
-
Save pathcl/0dd7320326605af31eb0 to your computer and use it in GitHub Desktop.
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/env python | |
import threading, paramiko | |
cmd = "someCommand" | |
outlock = threading.Lock() | |
def workon(host): | |
try: | |
ssh = paramiko.SSHClient() | |
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | |
ssh.connect(host, username='someUser', password='somePass') | |
stdin, stdout, stderr = ssh.exec_command(cmd) | |
stdin.write('xy\n') | |
stdin.flush() | |
with outlock: | |
print host | |
print stdout.readlines() | |
except paramiko.AuthenticationException: | |
print "FAIL" + host | |
def main(): | |
hosts = open('hosts.txt') | |
threads = [] | |
for h in hosts: | |
h = h.rstrip() | |
t = threading.Thread(target=workon, args=(h,)) | |
t.start() | |
threads.append(t) | |
for t in threads: | |
t.join() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment