Advertisement
Guest User

Untitled

a guest
Jan 8th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. import sys
  2. import paramiko
  3.  
  4. def execute_command_on_remote_machine(ip_addr, command):
  5. try:
  6. client = paramiko.SSHClient()
  7. client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  8.  
  9. client.connect(str(ip_addr), username='root', password='****')
  10. chan = client.get_transport().open_session()
  11. #chan.get_pty()
  12.  
  13. stdin, stderr, stdout = [], [], []
  14. stdin, stdout, stderr = client.exec_command(command, get_pty=True)
  15.  
  16. err_list = [line for line in stderr.read().splitlines()]
  17. out_list = [line for line in stdout.read().splitlines()]
  18.  
  19. client.close()
  20. return out_list, err_list
  21. except Exception, e:
  22. print str(e)
  23. sys.exit(1)
  24.  
  25.  
  26. output, error = execute_command_on_remote_machine("*.*.*.*", "dinesh")
  27.  
  28. print "Output is - ",output
  29. print "Error is - ",error
  30.  
  31. D:dsp_jetbrainsAWS_Persistence>python chk.py
  32. Output is - ['bash: dinesh: command not found']
  33. Error is - []
  34.  
  35. D:dsp_jetbrainsAWS_Persistence>python chk.py
  36. Output is - ['lsof: unknown file struct option: d', 'lsof: unknown file struct
  37. option: i', 'lsof: unknown file struct option: n', 'lsof: unknown file struct op
  38. tion: e', 'lsof: unknown file struct option: s', 'lsof: unknown file struct opti
  39. on: h', 'lsof 4.87', ' latest revision: ftp://lsof.itap.purdue.edu/pub/tools/uni
  40. x/lsof/', ' latest FAQ: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/FAQ', ' l
  41. atest man page: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/lsof_man', ' usag
  42. e: [-?abhKlnNoOPRtUvVX] [+|-c c] [+|-d s] [+D D] [+|-f[gG]] [+|-e s]', ' [-F [f]
  43. ] [-g [s]] [-i [i]] [+|-L [l]] [+m [m]] [+|-M] [-o [o]] [-p s]', '[+|-r [t]] [-s
  44. [p:s]] [-S [t]] [-T [t]] [-u s] [+|-w] [-x [fl]] [-Z [Z]] [--] [names]', "Use t
  45. he ``-h'' option to get more help information."]
  46. Error is - []
  47.  
  48. chan.get_pty()
  49.  
  50. stdin, stdout, stderr = client.exec_command(command, get_pty=True)
  51.  
  52. stdin, stdout, stderr = client.exec_command(command)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement