Send me email everytime a certain file is accessed from my apache server

1

1

I want to have my server send me an email every time someone accesses a PDF file on my webserver.

Perhaps:

tail -f /var/log/apache.log | grep pdf > ??something??

How would I generate a new email message each time this tail/grep outputs something? How could I have that running as a background script?

Rob Reid

Posted 2014-02-10T11:27:53.200

Reputation: 11

Answers

2

You may achieve such a thing by playing with the inotifywait and inotifywatch commands, from the inotify-tools package.

Example with inotifywait:

inotifywait -m -e access -e open -e modify /var/www/html/index.html

AgentSteel

Posted 2014-02-10T11:27:53.200

Reputation: 21

Thanks. For now I got the following sh script working. It fits in my current experience level. I may try inotifywait later.`#!/bin/bash FILE=/var/log/apache2/access.log TERM="pdf"

while read line; do echo $line | grep $TERM > /dev/null && echo $line | mail -s "new $TERM access" something@gmail.com done < <(tail -1f $FILE)` – Rob Reid – 2014-02-12T18:02:03.620