Let me point this script in Python to get the email notification dell'avvenuto root user login.
Create a new file / root / login-notify.py and customize
(If you create it is different from root's home directory)
import smtplib, sys, MimeWriter, StringIO, base64
import os
import re
def mail (serverURL = None, sender = "to =", subject = "text ="):
message = StringIO.StringIO ()
writer = MimeWriter.MimeWriter (message)
writer.addheader ('Subject', subject)
writer.startmultipartbody ('mixed')
Part writer.nextpart = ()
part.startbody body = ('text / plain')
body.write (text)
writer.lastpart ()
# Send the mail
smtp = smtplib.SMTP (serverURL)
SMTP.sendmail (sender, to, message.getvalue ())
smtp.quit ()
if __ name__ == "__main__":
put, get = os.popen4 ("who")
# Customize the text below with the server, sender, recipient, subject, text message
mail ('localhost', 'from@mail.com', 'destination@mail.com', 'User login', get.readlines ())
Make the script executable with chmod + x / usr / bin / python / root / login-notify.py.
To make sure that the script is run at login just add to the file / root / .bashrc / usr / bin / python / root / login-notify.py.
I hope you find it useful. Agree course recommendations and improvements.
Related Articles



