inotify, inotify-tools and incron: a great discovery to replace dnotify

Translation of the original in Catalan. Read it in: CatalàCastellano

Quite a few years ago, I talked about dnotify, it is a tool that allowed us to know when there was a change in the files of a directory, and then we took the opportunity to launch a process when the event occurred. Since the internal architecture of the program mentioned was not too good (it monitored changes by pooling) and due to the improvements of the new kernels, the concept of inotify has been used instead: inotify is a Linux kernel subsystem that provides file system event notification..

So, inotify-tools are the tools that allow us to use this kernel functionality from user application space. Really amazing. They allow monitoring a file, generating statistics about it, launching associated processes when a given change in the file is detected, etc. But perhaps the functionality that has interested me the most is the library it offers to program applications using the inotify features.

Specifically these libraries are the ones needed to compile incron. For me the most brilliant end application of all: it is an 'inotify cron'. Basically the tool consists of two parts, a dameon and a table of actions. This table is used in a way similar to the cron service. The difference is that the events are not clock signals, but captures of events of the file system.

An example of what the incrontab -l may look like:

/var/mail IN_CLOSE_WRITE abc $@/$#

This captures the event every time a file has been changed (IN_CLOSE_WRITE) inside the /var/mail directory, then it launches the program abc passing the path/file_name as a parameter. As you can see the power is infinite and the simplicity of use is impressive. Perhaps what I like the most is how easy it is to have all the directories I am monitoring and the associated actions centralised. For example, it is ideal for keeping an RSS of new music, video, downloads, etc.

5 comments

Comments from the old blog, as they were written. Comments are closed.

  1. brainstorm

    Yet another idea: A esCERT tenim un projectista al que li hem encarregat (fa unes setmanes) que integri inotify amb bacula, seria com un tripwire-ng, notificant dels canvis al FS instantàniament, comparant hashos, continguts, etc...

    Per a detectar intrusions sense que a un atacant doni temps d'esborrar evidències (la finestra d'oportunitat que donaria un cron stàndar, p.ex)...

    A més, pròpiament com a sistema de backups a curt termini pot anar de perles (d'aqui la idea d'integrar-ho amb bacula).

  2. —

    [1]

    Ostres, és súper interessant... quan tingueu alguna cosa digue-m'ho ,si us plau. Ja que encara no me liat amb el Bacula, però ho tindria en compte fer-ho.

    Per cert, saps d'alguna comparació entre Bacula i Amanda?

  3. Jordi

    Encara no t'ha arribat el Dell XPS m1330??

    Estic esperant el review amb candeletesssss :D

    Salut!

  4. —

    [3]

    Doncs hem sap greu però hauràs de seguir esperant. Perquè malgrat ja el tinc i a més tinc un milió de coses a explicar sobre ell. No tinc pas de temps de liar-me a escriure al blog com hauràs notat vaig a contra rellotge per 2 projectes de la feina i no faig res més que treballar tot el dia i la part de la nit q m'aguanta el cos. Així doncs, hauràs de tenir paciència.

    La valoració boníssima... un 8.5 sobre 10. Però pensa també que jo sóc molt exigent. Per cert, això de tenir 4Gb de RAM és un luxe no ho canvio per res del món. De fet, divendres m'arriba un servidor HP que m'he comprat per casa i tb li he posat 4Gb de RAM per llençar diverses màquines virtuals sobre d'ell.

  5. brainstorm

    [2] Doncs no en sé de cap comparativa "seriosa", però almenys dos colegues que treballen a universitats han migrat i estan molt contents... sembla que avui en dia bacula és "the way to go" en temes de backup lliure.

    Concretament han migrat de amanda->bacula un cas i l'altre de legato (sun storedge enterprise)->bacula (en aquest cas encara estan en proves, xo sembla que es quedaran amb aquesta solució).

    Vagi bé mestre !