Advertisement
Guest User

Untitled

a guest
Oct 13th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import ssh
  5. from multiprocessing import Pool
  6. import getpass
  7.  
  8. hostnames = [HOST1, HOST2]
  9. user = USERNAME
  10. pw = getpass.getpass("Enter ssh password:")
  11.  
  12. def processFunc(hostname):
  13. handle = ssh.SSHClient()
  14. handle.set_missing_host_key_policy(ssh.AutoAddPolicy())
  15. handle.connect(hostname, username=user, password=pw)
  16. print("child")
  17. stdin, stdout, stderr = handle.exec_command("ls -l /var/log; sleep 5")
  18. cmdOutput = ""
  19. while True:
  20. try:
  21. cmdOutput += stdout.next()
  22. except StopIteration:
  23. break
  24. print("Got output from host %s:%s" % (hostname, cmdOutput))
  25. handle.close()
  26.  
  27. pool = Pool(len(hostnames))
  28. pool.map(processFunc, hostnames, 1)
  29. pool.close()
  30. pool.join()
  31.  
  32. ## If you want to compare speed:
  33. # for hostname in hostnames:
  34. # processFunc(hostname)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement