directory:monitor_a_directory_for_changes:using_incron
This is an old revision of the document!
Table of Contents
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
NOTE: It is suggested to change /etc/incron.allow and /etc/incron.deny if this will be used as a normal 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!
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.
directory/monitor_a_directory_for_changes/using_incron.1611660041.txt.gz ยท Last modified: 2021/01/26 11:20 by peter