Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

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
share|improve this answer
    
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 Feb 12 at 18:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.