Article 5ES6K tail log file and send email on event

tail log file and send email on event

by
aristosv
from LinuxQuestions.org on (#5ES6K)
I am looking for a way to tail a log file, and if the words "Unable to" appear in the log file, send an email to me.

Code:while true ; do [ $(tail -n 1 /var/log/freqtrade1.log | grep 'Unable to' | wc -l) -gt 0 ] && printf "To: $receipient_email\nFrom: $sender_email\nSubject: $subject\n\n$body" | msmtp -a gmail $receipient_email ; doneThe above works, but it takes a few minutes for the next line to appear in the log file, so it keeps reading the last like and floods me with emails.

Also I want to include the line from the log file, into the body of the email.

How can I do this?
Thankslatest?d=yIl2AUoC8zA latest?i=MK-oSiFhHCY:p2O3A-A75T0:F7zBnMy latest?i=MK-oSiFhHCY:p2O3A-A75T0:V_sGLiP latest?d=qj6IDK7rITs latest?i=MK-oSiFhHCY:p2O3A-A75T0:gIN9vFwMK-oSiFhHCY
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments