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 test@example.com; 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)
curled your URL in a tight loop?). Just use a log analyzer for Apache. – Satō Katsura Sep 15 '17 at 14:08example.com/superimportantfile.pdf?src=JH2KS79x0v9t8(with an impossible-to-guess pattern) to someone and you want to be informed by email. – Basj Sep 15 '17 at 14:11curled that page in a tight loop? – Satō Katsura Sep 15 '17 at 14:14JH2KS79x0v9t8to trigger an email. And this pattern is only communicated to one person that I know. – Basj Sep 15 '17 at 14:23greppattern searches through pipes :-)You said in the question, alternatively, would it be possible to send an email twice a day but in the comments that this is for to be quickly informed. If you get emails in predetermined intervals, it will not be as quick as I think you want it to be. But I would redirect the output of the command/script to a file and check it periodically if it's empty. If you want it I'll write my idea more briefly.
– Wax Sep 15 '17 at 15:08