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
Joel
  • 439
  • 2
  • 5
  • 11

2 Answers2

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.

Craig Watson
  • 9,370
  • 3
  • 30
  • 46
  • (+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 06 '13 at 09: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.

Joel
  • 439
  • 2
  • 5
  • 11