I want to automatically run a script whenever new files are copied into a particular directory. In other words, is there a way in Linux to "watch" a directory for changes and then run something in response to the change?
|
If you're lucky enough to be on a debian-based distribution,
If you want to handle this within your own program, dnotify is also the API you want to use. |
|||||||||||||||||
|
|
You can run a script with the inotify-tools, something like this. It will watch the directory for changes in modified files, new files, and deleted files, then it will execute the script.
|
|||
|
|
incron is basically what you want, I think. It uses inotify as the notification mechanism (which, as others have pointed out, supercedes dnotify), but doesn't require a script that continuously runs, using inotifywait or similar (although, obviously, the incron daemon is running all the time). System-wide 'crontabs' and user 'crontabs' are supported in a similar way to standard cron, but rather than specifying times as triggers, inotify events and files/directory names are used. incron is packaged for many distributions, including Ubuntu and Debian, I believe. |
|||
|
|