Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


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

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" done < <(tail -1f $FILE) – Rob Reid Feb 12 '14 at 18:02

Your Answer


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.