I am new to dnotify/inotify command. Can any one help me how to write a script such that it continuously monitors a directory and indicates that there is some change or modification to it.
Join Stack Overflow to learn, share knowledge, and build your career.
|
Inotify itself is a kernel module accesible via calls from e.g. a C program. http://www.ibm.com/developerworks/linux/library/l-ubuntu-inotify/ There is an application suite called inotify-tools, which contains:
and
You can use inotify directly from command line, e.g. like this to continuously monitor for all changes under home directory (may generate lots of output):
And here is a script that monitors continuously and reacts to Apache log activity, copied from the man file of inotifywait:
|
|||||||||||||
|
|
Below is what I use to see operations on an individual file. "-m" causes monitoring vs. exit after just one event. To get timestamps, you need at least 3.13 version of inotify-tools, but if that is not important (or not available on your OS or hard to update to) you can skip the timefmt and format options. "cat /etc/resolv.conf" in another shell leads to the results below:
inotifywait has options for monitoring directories as well, so check the manpage. Add -r for recursive to monitor children of a dir. Here's an example with the commands I typed in a different window shown with "->" prefix:
After the above, I tried to remake the tmpdir ("mkdir tmpdir") but got no output from that. The new tmpdir is not the same directory as the old tmpdir. Time to just ^C and stop itnotifywait. |
|||
|
|
|
As I said on https://superuser.com/a/747574/28782, I made a helper script that uses inotifywait without some of its direct limitations: inotifyexec Usage example (supposing you've added it in your system path as executable):
|
||||
|
|