3

I'm looking for shell command like the kernel's inotify function.

Is there a command that will monitor a directory, that could be used like this:

while [ 1 ]; do
   name-of-monitor-program . && echo "something changed"
done

2 Answers 2

4

What you're looking for is incron.

incron and incrontab are inotify cron applications that instead of firing events according to time, it watches a certain folder/file and fires scripts/commands based on what happens to that folder/file, and even interpolate the name of that file/folder into the command.

Events are explained here: http://linux.die.net/man/5/incrontab

A typical use-case would be "watch this folder for incoming files dumped via (S)FTP and transcode them", rather than having a cron that runs every minute and checks for new files.

It's also worth noting that the developer classes incron as Alpha software. I have used it in a production environment before with no issues, but it's worth considering.

1
  • (+1) Thanks Craig. This is good to know about. I can already think of uses for it. However, it's not quite what I'm after in this case. I'm looking for something I can run in the foreground without depending on system config, root access etc. I tried co-opting it to this end, but gave up.
    – Joel
    Oct 6, 2013 at 9:50
1

I found iwatch.

I don't know why I didn't think of doing apt-cache search inotify before asking this question.

This is how I used it:

iwatch -r -c "PATH=$PATH; program-i-wanted-to-run" .

I had to pass the PATH environment variable in, because when the program is spawned it doesn't inherit the shell's environment variables.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .