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?
Thanks


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?
Thanks