Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import paramiko
- import select
- import smtplib
- from email.mime.multipart import MIMEMultipart
- from email.mime.text import MIMEText
- client = paramiko.SSHClient()
- client.load_system_host_keys()
- client.connect('192.168.0.11', port=22, username='root', password='root')
- transport = client.get_transport()
- channel = transport.open_session()
- channel.exec_command("tail -f /var/log/auth.log")
- while True:
- rl, wl, xl = select.select([channel],[],[],0.0)
- if len(rl) > 0:
- output = channel.recv(1024).decode("utf-8")
- print (output)
- fromaddr = "xxxxxxxxxx@gmail.com"
- toaddr = "xxxxxxxx@gmail.com"
- msg = MIMEMultipart()
- msg['From'] = fromaddr
- msg['To'] = toaddr
- msg['Subject'] = "log file alerts"
- msg.attach(MIMEText(output))
- server = smtplib.SMTP('smtp.gmail.com', 587)
- server.starttls()
- server.login(fromaddr, "password")
- text = msg.as_string()
- server.sendmail(fromaddr, toaddr, text)
Add Comment
Please, Sign In to add comment