I want to monitor the maillog file in real time and send a mail when a certain grep condition is met. Every time the grep condition is met a mail will be sent. I wish to ignore all grep conditions 30 mins after each mail and thereafter continue monitoring.
For example:
- Condition is met, mail is sent
- 30 mins no mail even if condition is met.
- After 30 mins again condition is met and a mail is triggered.
- Again for next 30 mins no mail even if condition is met.
and so on.
I am doing the following:
tail -F -n0 /var/log/maillog | \
grep -v --line-buffered 'status=sent' | \
grep --line-buffered -v 'relay=local' | \
grep --line-buffered 'relay=' | \
while read line
do
echo "$line" | \
mail -s Test mail@group.com
done
Now i am not sure how to prevent mail sending 30 mins after the event is triggered.