Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # sudo pip install pygtail
- # created by hahungkk@gmail.com
- from pygtail import Pygtail
- import sys
- import time
- import smtplib
- #Gmail only
- GMAIL_USER = ''
- GMAIL_PASSWORD = ''
- RECIPIENT = ''
- SUBJECT = 'Mail send from tailf log apache'
- LOG_PATH = '/home/cherry/sudo.log'
- LIST_STRING_TO_PROCESS = ['XXX', 'AAA', 'BBB']
- def send_email(body):
- FROM = GMAIL_USER
- TO = RECIPIENT if type(RECIPIENT) is list else [RECIPIENT]
- TEXT = body
- # Prepare actual message
- message = """From: %s\nTo: %s\nSubject: %s\n\n%s
- """ % (FROM, ", ".join(TO), SUBJECT, TEXT)
- try:
- server = smtplib.SMTP("smtp.gmail.com", 587)
- server.ehlo()
- server.starttls()
- server.login(GMAIL_USER, GMAIL_PASSWORD)
- server.sendmail(FROM, TO, message)
- server.close()
- print('successfully sent the mail')
- except:
- print("failed to send mail")
- while True:
- for line in Pygtail(LOG_PATH):
- if any(x in line for x in LIST_STRING_TO_PROCESS):
- send_email(line)
- time.sleep(0.5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement