Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pexpect import pxssh
- try:
- s = pxssh.pxssh()
- hostname = '***'
- username = '***'
- password = '***'
- s.login (hostname, username, password)
- print("logged in")
- while 1:
- time.sleep(3)
- s.sendline('sudo lxc exec abc-1 -- /root/tail /usr/local/var/syslog')
- s.prompt()
- msg = (s.before).decode("utf-8")
- with open("Output.txt", "a") as f:
- f.write(msg + 'rn')
- s.logout()
- except pxssh.ExceptionPxssh as e:
- print ("pxssh failed on login.")
- print (str(e))
- class ReadLogs(threading.Thread):
- def __init__(self, erv):
- threading.Thread.__init__(self)
- self.erv = erv
- self.s = pxssh.pxssh()
- hostname = '***'
- username = '***'
- password = '***'
- self.s.login(hostname, username, password)
- def run(self):
- while 1:
- print('running thread for ' + self.erv)
- time.sleep(5)
- self.s.sendline('sudo lxc exec ' + self.erv + ' -- /root/tail /usr/local/var/syslog')
- self.s.prompt()
- self.msg = (self.s.before).decode("utf-8")
- with open(self.erv + "_logs.txt", "a") as f:
- f.write(self.msg + 'rn')
- self.s.logout()
- if __name__ == '__main__':
- c1 = ReadLogs("abc-1")
- c1.start()
- c2 = ReadLogs("abc-2")
- c2.start()
- logged in
- running thread for abc-1
- running thread for abc-2
- running thread for abc-1
- running thread for abc-1
- running thread for abc-1
- running thread for abc-2
- running thread for abc-1
- running thread for abc-2
- running thread for abc-1
- running thread for abc-2
- running thread for abc-2
- running thread for abc-1
- running thread for abc-2
- running thread for abc-1
- running thread for abc-1
- running thread for abc-1
- running thread for abc-1
- running thread for abc-2
- running thread for abc-1
- running thread for abc-1
- running thread for abc-1
Add Comment
Please, Sign In to add comment