Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement