Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question

4 Answers 4

up vote 13 down vote accepted

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.

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.

share|improve this answer
    
Could you provide an example? Links to manual pages are welcome too, I could not find the one for incron, the inoticoming one is here. –  Lekensteyn May 19 '11 at 14:15
    
For incron see the manpages of incrond, incrontab and incron.conf –  Florian Diesch May 19 '11 at 14:22
1  
I've edited your answer in a way I wanted to see it. I copied it from the packages descriptions, please be so extensive in the future when naming programs :) –  Lekensteyn May 19 '11 at 15:01

Another utility worth to know is fileschanged (man page here), that can monitor filesystem event on selected files or directories, for example the following command

fileschanged -s created -t1 $PWD

should 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 can iwatch as noted in another answer), unlike incron and inoticoming.

share|improve this answer

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.

share|improve this answer

inotify man page is located there

if you prefer python scripts, you can use pyinotify

share|improve this answer

Your Answer

 
discard

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.