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
incron
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.Another utility worth to know is
fileschanged
(man page here), that can monitor filesystem event on selected files or directories, for example the following commandshould monitor the current directory for file creation events, writing the name of the created file on
stdout
with a 1sec timeout.fileschanged
can watch folders recursively (as caniwatch
as noted in another answer), unlikeincron
andinoticoming
.inotify man page is located there
if you prefer python scripts, you can use pyinotify