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
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.
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.