Advertisement
Guest User

Untitled

a guest
May 17th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. import os
  2. import sys
  3. import paramiko
  4. import getpass
  5. import socket
  6. from multiprocessing import Pool
  7.  
  8.  
  9. def processFunc(hostname):
  10. handle = paramiko.SSHClient()
  11. handle.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  12. handle.connect(hostname, username=user, password=pw)
  13. print("child")
  14. stdin, stdout, stderr = handle.exec_command("show clock")
  15. cmdOutput = ""
  16. while True:
  17. try:
  18. cmdOutput += stdout.next()
  19. except StopIteration:
  20. break
  21. print("Got output from host %s:%s" % (hostname, cmdOutput))
  22. handle.close()
  23.  
  24. user = "sup"
  25. f= open('csip.txt','r')
  26. hostnames = []
  27. for line in f:
  28. hostname = line.strip()
  29. hostnames.append(hostname)
  30. pw = getpass.getpass("Enter ssh password:")
  31.  
  32. if __name__ == "__main__":
  33. pool = Pool(processes=4)
  34. pool.map(processFunc, hostnames, 1)
  35. pool.close()
  36. pool.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement