User Tools

Site Tools


directory:monitor_a_directory_for_changes:using_incron

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
directory:monitor_a_directory_for_changes:using_incron [2021/01/26 11:28] peterdirectory:monitor_a_directory_for_changes:using_incron [2022/06/13 09:17] (current) – removed peter
Line 1: Line 1:
-====== 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 ===== 
- 
-<code bash> 
-sudo apt install incron 
-</code> 
- 
- 
----- 
- 
-===== Change Permissions ===== 
- 
-Add users to the **/etc/incron.allow** file who are allowed to use incron. 
- 
-<file bash /etc/incron.allow> 
-peter 
-</file> 
- 
-<WRAP info> 
-**NOTE:**  One user per line. 
- 
-**/etc/incron.deny** can also be used to specifically prevent usage of incron by a user. 
-</WRAP> 
- 
----- 
- 
-===== Monitor ===== 
- 
-Edit the incron table: 
- 
-<code bash> 
-incrontab -e 
-</code> 
- 
-and populate with: 
- 
-<code> 
-/home/peter/some_dir_to_monitor IN_CLOSE_WRITE,IN_MOVED_TO /home/peter/some_program_to_run $@/$# 
-</code> 
- 
-<WRAP info> 
-**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: 
- 
-  * **$$**:  Prints a dollar sign. 
-  * **$@**:  The watched filesystem path. 
-  * **$#**:  The event-related file name. 
-  * **$%**:  The event flags/time (textually). 
-  * **$&**:  The event flags.time (numerically). 
- 
- 
-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. 
- 
-</WRAP> 
- 
----- 
- 
-===== List the incron table ===== 
- 
-<code bash> 
-incrontab -l 
-</code> 
  
directory/monitor_a_directory_for_changes/using_incron.1611660485.txt.gz · Last modified: 2021/01/26 11:28 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki