Using inotify to monitor the filesystem

Slashdot it! Delicious Share on Facebook Tweet! Digg!


inotifywatch , another inotify tool, works similarly to inotifywait except that it only collects information. It does not execute actions. The options in the program are almost the same as those in inotifywait . inotifywatch is primarily useful for identifying problems and getting an overview of what is currently happening in a filesystem or directory.


Another more straightforward possibility for starting a command or a script, which can then be used to execute multiple commands, comes in the form of the iWatch tool [2]. It was developed with an eye for simplicity. Listing 2 shows the syntax for the command. Ordinarily it will not be necessary to enter this set of characters. UTF-8 is preset.

Listing 2

Running iWatch

$ iwatch -c "command line" [-C character set] [-e Event]...

If you designate command lines as an argument of -c and the lines contain empty spaces, then you will need to enclose these with single quotation marks. The single quotation marks prevent shell functions from expanding, whereas double quotation marks permit expansion. The quotation marks also make it possible to use complex command lines with individual commands separated with semicolons (; ). Interestingly enough, the possibility of accessing certain parts of the event also exists here. For example, the place holder %e stands for the name of the event and %f for the path and name of the triggering file.

Listing 3 shows a simple example that uses iWatch . By using *.adoc , each modification to the ASCIIDOC source texts triggers a new processing event. The program does this by recompiling the "master" file route5-2016.adoc with a2x .

Listing 3

Example using iWatch

$ iwatch -c "a2x -v -a lang=en -f pdf -dbook route5-2016.adoc; date" -e modify *.adoc &

The -r option causes iWatch to work recursively. Using -d , you switch the program into daemon mode, similar to inotifywait -d or inotifywait -m . In this mode, it is a configuration file that essentially controls the behavior of the program. With -t , you activate a list of positive filter functions. The iWatch tool evaluates the list when monitoring the files.

While the workings of iWatch are simple, there are two downsides. Since the program is written in Perl, you need to resolve a number of dependencies. Practically speaking, this means that conflicts regularly occur among the versions. In these situations, the only thing to do is to uninstall and remove all of the dependencies and then reinstall the program. The other downside is that iWatch does not have a man page. Instead, the option -h takes you to extensive help.

You will find complete documentation of this program on the homepage [3]. There you will also learn how to define the files that should not deliver a trigger by using the -x <Exception(n)> and -X <Pattern> options.

Buy this article as PDF

Express-Checkout as PDF

Pages: 3

Price $0.99
(incl. VAT)

Buy Ubuntu User

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content