Perhaps you've got a vendor that sends you a file every day early in the morning, and you're waiting for the file before processing it. Rather than check every 15 minutes to see if the file has been uploaded, you could instead trigger an event the second the file arrives. But if you're not the one pushing data around or you don't have a FTP/SFTP/FTPS/etc file server that has event triggers, you can still write a script to handle events.

Enter inotify-tools. A handy set of tools that can capture filesystem events and then you can take action based on them. For example you could watch when a file in a directory has been modified and send an email alert!

Here is an example bash script:

inotifywait -mr --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' \
-e close_write,moved_to "/home/username/incoming" | while read date time file; do

        sendmail "" << EOF

change event triggered on $FILECHANGED
echo "If you see this message then an error occurred in inotify"


Due to the way inotify works, high-frequency updates might not all be caught by inotify. So if you are putting several files per second into a directory it might not catch all the events. You can minimize this by using nohup when you call other programs.

In CentOS the inotify-tools package is in the EPEL and RPMForge repository, so if you already have the repository you can just install it via "yum install inotify-tools".

For More Information

If you get stuck and want to hear how RDA can help your business, please give us a call or contact us using the form on the right!