Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I want to run a process when a file is written to a directory on Ubuntu. I understand I can write a monitor to do this. (ie not an event based trigger but a 'monitor').

To implement this - other than writing a for loop of infinite duration in C that polls the directory - what steps would you take to implement this?

What steps would you take to implement a monitor on Ubuntu that runs a process (another application) when a file is written to a directory?

(The reason that you'd do this is the that process writing the file is under a limited set of permissions (eg tomcat6) but the executed process (an existing software package) needs root (ie to run a process in a chroot jail))

share|improve this question

2 Answers 2

up vote 1 down vote accepted

If you're writing C, why not just use the inotify lib?

Or if you're just writing a simple shell script, you can use watch. Both are in all modern Linux variants.

share|improve this answer

See this StackOverflow question:

http://stackoverflow.com/questions/511463/monitor-directory-for-changes

Alternatively if installing inotify is not possible checkout these programmatic means:

http://aplawrence.com/Unixart/watchdir.html

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.