Advertisement
Guest User

Untitled

a guest
Aug 5th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. stdin, stdout, stderr = ssh.exec_command('cmd /c dir "D:"')
  2.  
  3. stdin, stdout, stderr = ssh.exec_command('if [[ -d /cygdrive/d/log ]]; then echo Exists; fi')
  4.  
  5. if_exist_path = "cmd /c if exist "" + log_path + "" echo Exists"
  6. stdin, stdout, stderr = ssh.exec_command(if_exist_path)
  7.  
  8. import paramiko
  9. ssh = paramiko.SSHClient()
  10. ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  11. ssh.connect("10.9.8.7", username="FakeUser", password="FakePassword")
  12. log_path = "D:\Log"
  13. if_exist_path = "cmd /c if exist "" + log_path + "" echo Exists"
  14. print("Var 'if_path_exist' is: {}".format(if_exist_path))
  15. stdin, stdout, stderr = ssh.exec_command(if_exist_path)
  16. stdoutput = stdout.readlines()
  17. stderror = stderr.readlines()
  18. print("First Stdout is {}".format(stdoutput))
  19. print("First Stderr is {}".format(stderror))
  20. print("")
  21. stdin, stdout, stderr = ssh.exec_command('cmd /c dir "D:\Log"')
  22. stdoutput = stdout.read()
  23. stderror = stderr.read()
  24. print("Second Stdout is {}".format(stdoutput))
  25. print("Second Stderr is {}".format(stderror))
  26. print("")
  27. stdin, stdout, stderr = ssh.exec_command('cmd /c dir "D:"')
  28. stdoutput = stdout.read()
  29. stderror = stderr.read()
  30. print("Third Stdout is {}".format(stdoutput))
  31. print("Third Stderr is {}".format(stderror))
  32. print("")
  33. stdin, stdout, stderr = ssh.exec_command('cmd /c dir "D:\"')
  34. stdoutput = stdout.read()
  35. stderror = stderr.read()
  36. print("Fourth Stdout is {}".format(stdoutput))
  37. print("Fourth Stderr is {}".format(stderror))
  38. print("")
  39. stdin, stdout, stderr = ssh.exec_command('cmd /c dir "D:Log"')
  40. stdoutput = stdout.read()
  41. stderror = stderr.read()
  42. print("Fifth Stdout is {}".format(stdoutput))
  43. print("Fifth Stderr is {}".format(stderror))
  44. print("")
  45. stdin, stdout, stderr = ssh.exec_command('cmd /c dir "D:Log"')
  46. stdoutput = stdout.read()
  47. stderror = stderr.read()
  48. print("Sixth Stdout is {}".format(stdoutput))
  49. print("Sixth Stderr is {}".format(stderror))
  50. print("")
  51.  
  52. C:Scripts>SO_Test.py
  53. Var 'if_path_exist' is: cmd /c if exist "D:Log" echo Exists
  54. First Stdout is []
  55. First Stderr is []
  56.  
  57. Second Stdout is Volume in drive D is Apps
  58. Volume Serial Number is xxxx-xxxx
  59.  
  60. Directory of D:
  61.  
  62.  
  63. Second Stderr is File Not Found
  64.  
  65.  
  66. Third Stdout is Volume in drive D is Apps
  67. Volume Serial Number is xxxx-xxxx
  68.  
  69. Directory of D:
  70.  
  71. 01/26/2017 10:49 PM <DIR> Log
  72. 01/12/2017 11:34 AM 12,887 Blah.ps1
  73. 01/12/2017 01:16 PM 12,082 result.txt
  74. 12/12/2016 03:39 PM 23,340 Blahv201.zip
  75. 04/15/2017 10:37 PM <DIR> Company
  76. 01/27/2017 08:19 PM <DIR> CompanyBackup
  77. 01/12/2017 01:08 PM 10,060 Untitled1.ps1
  78. 4 File(s) 58,369 bytes
  79. 3 Dir(s) 175,276,904,448 bytes free
  80.  
  81. Third Stderr is
  82.  
  83. Fourth Stdout is
  84. Fourth Stderr is sh: -c: line 0: unexpected EOF while looking for matching `"'
  85. sh: -c: line 1: syntax error: unexpected end of file
  86.  
  87. Fifth Stdout is Volume in drive D is Apps
  88. Volume Serial Number is xxxx-xxxx
  89.  
  90. Directory of D:
  91.  
  92.  
  93. Fifth Stderr is File Not Found
  94.  
  95. Sixth Stdout is Volume in drive D is Apps
  96. Volume Serial Number is xxxx-xxxx
  97.  
  98. Directory of D:
  99.  
  100.  
  101. Sixth Stderr is File Not Found
  102.  
  103. if os.path.isdir("/test/to/dir") == True:
  104.  
  105. print('dir exists ')
  106.  
  107. # you next actions
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement