User Tools

Site Tools


directory:monitor_a_directory_for_changes:using_incron

This is an old revision of the document!


Directory - Monitor a directory for changes - Using incron

incron is like cron but instead of time-based events, the events are based on file notifications.


Install incron

sudo apt install incron

Change Permissions

Add users to the /etc/incron.allow file who are allowed to use incron.

/etc/incron.allow
peter

NOTE: One user per line.

/etc/incron.deny can also be used to specifically prevent usage of incron by a user.


Monitor

Edit the incron table:

incrontab -e

and populate with:

/home/peter/some_dir_to_monitor IN_CLOSE_WRITE,IN_MOVED_TO /home/peter/some_program_to_run $@/$#

NOTE: The format is very picky; use spaces, not tabs!

  • The format is path mask command.

This monitors the directory for changes and runs the program passing along some parameters:

  • $@/$#: Provides a full path to the file affected.

Other parameters can also be included, such as:

  • Event time as text ($%) or a number ($&).

Events to monitor include:

  • IN_ACCESS: If a file is accessed or read.
  • IN_ATTRIB: If metadata of a file change (e.g. timestamps, permissions).
  • IN_CLOSE_WRITE: If a file opened for writing is closed.
  • IN_CLOSE_NOWRITE: If a file or directory not opened for writing is closed.
  • IN_CREATE: If a file or directory is created in a watched directory.
  • IN_DELETE: If a file or directory is deleted from a watched directory.
  • IN_DELETE_SELF: If a watched file or directory is deleted (or moved to a different filesystem).
  • IN_MODIFY: If a file was modified.
  • IN_MOVE_SELF: If a watched file or directory is moved within the filesystem.
  • IN_MOVED_FROM: If a file or directory is moved out of the watched directory.
  • IN_MOVED_TO: A file or directory is moved to the watched directory.
  • IN_OPEN: A watched file or directory is opened.

List the incron table

incrontab -l
directory/monitor_a_directory_for_changes/using_incron.1611660348.txt.gz ยท Last modified: 2021/01/26 11:25 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki