Guest User

Untitled

a guest
Nov 24th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. from pexpect import pxssh
  2. try:
  3. s = pxssh.pxssh()
  4. hostname = '***'
  5. username = '***'
  6. password = '***'
  7. s.login (hostname, username, password)
  8. print("logged in")
  9. while 1:
  10. time.sleep(3)
  11. s.sendline('sudo lxc exec abc-1 -- /root/tail /usr/local/var/syslog')
  12. s.prompt()
  13. msg = (s.before).decode("utf-8")
  14. with open("Output.txt", "a") as f:
  15. f.write(msg + 'rn')
  16. s.logout()
  17. except pxssh.ExceptionPxssh as e:
  18. print ("pxssh failed on login.")
  19. print (str(e))
  20.  
  21. class ReadLogs(threading.Thread):
  22. def __init__(self, erv):
  23. threading.Thread.__init__(self)
  24. self.erv = erv
  25. self.s = pxssh.pxssh()
  26. hostname = '***'
  27. username = '***'
  28. password = '***'
  29. self.s.login(hostname, username, password)
  30.  
  31. def run(self):
  32. while 1:
  33. print('running thread for ' + self.erv)
  34. time.sleep(5)
  35. self.s.sendline('sudo lxc exec ' + self.erv + ' -- /root/tail /usr/local/var/syslog')
  36. self.s.prompt()
  37. self.msg = (self.s.before).decode("utf-8")
  38. with open(self.erv + "_logs.txt", "a") as f:
  39. f.write(self.msg + 'rn')
  40.  
  41. self.s.logout()
  42.  
  43. if __name__ == '__main__':
  44. c1 = ReadLogs("abc-1")
  45. c1.start()
  46. c2 = ReadLogs("abc-2")
  47. c2.start()
  48.  
  49. logged in
  50. running thread for abc-1
  51. running thread for abc-2
  52. running thread for abc-1
  53. running thread for abc-1
  54. running thread for abc-1
  55. running thread for abc-2
  56. running thread for abc-1
  57. running thread for abc-2
  58. running thread for abc-1
  59. running thread for abc-2
  60. running thread for abc-2
  61. running thread for abc-1
  62. running thread for abc-2
  63. running thread for abc-1
  64. running thread for abc-1
  65. running thread for abc-1
  66. running thread for abc-1
  67. running thread for abc-2
  68. running thread for abc-1
  69. running thread for abc-1
  70. running thread for abc-1
Add Comment
Please, Sign In to add comment