In this question, a solution was found to automatically send an email each time a specific URL is visited (such as ?src=foo), as seen in the Apache logs:
tail -F -n0 /var/log/apache2/other_vhosts_access.log | grep --line-buffered "?src=foo" | \
{ while IFS= read -r line; do echo "$line" | mail [email protected]; done } &
But the problem is that any other ressource being loaded on this page (images, favicon, etc.) have this pattern ?src=foo in the referrer column too:
www.example.fr:80 111.111.111.111 - - [12/Sep/2017:17:30:32 +0200] "GET /images/P26372.jpg
HTTP/1.1" 200 86276 "http://example.fr/?src=foo" "Mozilla/5.0"
Then I'm receiving 15 emails in a row with this method.
How to limit to do a "digest" of this?
I thought about limiting the search for the pattern inside "GET ... HTTP" so it would exclude a result in the referred column, but how to do this?
Or, alternatively, would it be possible to send only an email twice per day with all the results of grep? (no email sent is nothing is found)