Created
October 13, 2017 01:38
-
-
Save bongbongco/51534becd4ba5846f4b473e5f83f4185 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# -*- coding: utf-8 -*- | |
import ssh | |
from multiprocessing import Pool | |
import getpass | |
hostnames = [HOST1, HOST2] | |
user = USERNAME | |
pw = getpass.getpass("Enter ssh password:") | |
def processFunc(hostname): | |
handle = ssh.SSHClient() | |
handle.set_missing_host_key_policy(ssh.AutoAddPolicy()) | |
handle.connect(hostname, username=user, password=pw) | |
print("child") | |
stdin, stdout, stderr = handle.exec_command("ls -l /var/log; sleep 5") | |
cmdOutput = "" | |
while True: | |
try: | |
cmdOutput += stdout.next() | |
except StopIteration: | |
break | |
print("Got output from host %s:%s" % (hostname, cmdOutput)) | |
handle.close() | |
pool = Pool(len(hostnames)) | |
pool.map(processFunc, hostnames, 1) | |
pool.close() | |
pool.join() | |
## If you want to compare speed: | |
# for hostname in hostnames: | |
# processFunc(hostname) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment