how to put a trigger on a directory

I have a script that scans a directory and does some maintenance on the files in it. Another process creates the files in the directory (10 - 30 files per day).

The script is called via a daily cron job . What I need is to trigger the script on an event (each time a new file is created in the directory). I prefer this rather than increasing the frequency of the cron job.

How can I do that? is there a command or a program to install?

Thanks in advance for any help.


inoticoming

inoticoming is a daemon to watch a directory with Linux's inotify framework and trigger actions once files with specific names are placed in there.

For example it can be used to wait for .changes files uploaded into a directory and call reprepro to put them into your repository.

  • Manual page of inoticoming

incron

incron is an "inotify cron" system. It works like the regular cron but is driven by filesystem events instead of time events. This package provides two programs, a daemon called "incrond" (analogous to crond) and a table manipulator "incrontab" (like "crontab").

incron uses the Linux Kernel inotify syscalls.

like cron, each user can edit its own incron tables.

  • Manual page of incrond
  • Manual page of incrontab
  • Manual page of icron.conf

There is also a small program called iwatch - see the man page (this page is for Ubuntu precise (12.04), it has links to other ubuntu versions).

iwatch has the ability watch folders recursively (ie: subfolders too) and to send emails in response to file/directory events.