24

I'm looking at building a file system sync utility that monitors file system activity, but it appears that some of the file system monitoring features in the linux kernel are obsolete or not fully featured.

What my research as found

dnotify came first with notification has the features of notifying for delete,modify,access,attribs,create,move can determine file descriptor, however is now out dated by inotify and fanotify

inotify came out second with notification has the features of notifying access, modify, attrib, close, move, delete, create, etc however it does not give you a file descriptor or process and will be outdated by fanotify

fanotify is the latest which informs of access, modify, close, but does not inform of delete or attribs, but does provide file descriptor

I need a way of determining the process (e.g. from fd) and things like delete, modify, attribs, etc in order to sync everything, any suggestions? Unfortunately dnotify seems the best but most out-dated

ReDucTor
  • 313
  • 1
  • 2
  • 11

3 Answers3

8

You should use a library instead of inotify and friends - something like FAM or Gamin (it's the same API for both). This will make your program portable to other Unixes.

cnicutar
  • 164,886
  • 23
  • 329
  • 361
3

There's a good lib providing file descriptors or process with inotify. It has his own C API and the inotifywatch util (good for scripts), all in inotify-tools package.

I strongly disagree that fanotify will outdate inotify.

FAM and gamin are very good server/client options. Both of them use inotify as first option over the outdated dnotify and polls. I prefer gamin.

  • 3
    Out of interest, what are your reasons for the strong disagreement? – itsbruce Oct 29 '12 at 12:41
  • 2
    I am curious too - watching directories recursively with inotify is tricky at best. fanotify isn't directly comparable, but for monitoring entire disk volumes it is simpler and more reliable. – Peter Krnjevic Jul 17 '13 at 02:17
  • Unless you want to monitor it for things like "a file was renamed" or "a file was deleted" and then you're *still* out of luck. :/ – Jean-Paul Calderone Apr 25 '14 at 11:12
  • None of these seem to give process ID. "The inotify API provides no information about the user or process that triggered the inotify event." – Jacek Feb 05 '16 at 17:31
2

incron is a useful tool for the operations like this. You may create a configuration file for the directory or file that you want to watch.

http://inotify.aiken.cz/?section=incron&page=about&lang=en

in ubuntu

sudo apt-get install incron

/etc/incron.d/mynotification.conf

# notification for user creation
/home IN_ALL_EVENTS /opt/notify_user_created.sh $#
Fırat KÜÇÜK
  • 4,536
  • 1
  • 42
  • 52