Guest User

Untitled

a guest
Oct 25th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. import paramiko
  2. import select
  3. import smtplib
  4. from email.mime.multipart import MIMEMultipart
  5. from email.mime.text import MIMEText
  6.  
  7. client = paramiko.SSHClient()
  8. client.load_system_host_keys()
  9. client.connect('192.168.0.11', port=22, username='root', password='root')
  10. transport = client.get_transport()
  11. channel = transport.open_session()
  12. channel.exec_command("tail -f /var/log/auth.log")
  13. while True:
  14. rl, wl, xl = select.select([channel],[],[],0.0)
  15. if len(rl) > 0:
  16. output = channel.recv(1024).decode("utf-8")
  17. print (output)
  18. fromaddr = "xxxxxxxxxx@gmail.com"
  19. toaddr = "xxxxxxxx@gmail.com"
  20. msg = MIMEMultipart()
  21. msg['From'] = fromaddr
  22. msg['To'] = toaddr
  23. msg['Subject'] = "log file alerts"
  24. msg.attach(MIMEText(output))
  25. server = smtplib.SMTP('smtp.gmail.com', 587)
  26. server.starttls()
  27. server.login(fromaddr, "password")
  28. text = msg.as_string()
  29. server.sendmail(fromaddr, toaddr, text)
Add Comment
Please, Sign In to add comment