directory:run_a_command_upon_files_or_directories_changes
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
directory:run_a_command_upon_files_or_directories_changes [2021/01/26 01:30] – peter | directory:run_a_command_upon_files_or_directories_changes [2021/01/26 10:53] (current) – removed peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Directory - Run a Command Upon Files or Directories Changes ====== | ||
- | |||
- | Use either inotifywait or iwatch. | ||
- | |||
- | For example | ||
- | |||
- | <code bash> | ||
- | inotifywait -m -e modify, | ||
- | chmod 644 file; && \ | ||
- | chown blah:blah file; | ||
- | </ | ||
- | |||
- | <WRAP info> | ||
- | **NOTE:** | ||
- | |||
- | * **-m, --monitor**: | ||
- | * **-r, --recursive**: | ||
- | * Symbolic | ||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | ===== Using a BASH Script ===== | ||
- | |||
- | <file bash after-change.sh> | ||
- | #!/bin/bash | ||
- | # | ||
- | # Monitor the input directory and if any change occurs run the provided command: | ||
- | # | ||
- | # Usage: | ||
- | # | ||
- | |||
- | if [ $# -lt 3 ]; then | ||
- | echo " | ||
- | exit 1 | ||
- | fi | ||
- | |||
- | which inotifywait 2>&1 >/ | ||
- | |||
- | if [ " | ||
- | echo " | ||
- | exit 1 | ||
- | fi | ||
- | |||
- | dir=$1 | ||
- | shift | ||
- | cmd=$1 | ||
- | shift | ||
- | options=$* | ||
- | |||
- | inotifywait -q -r -m $dir $options | ||
- | eval $cmd | ||
- | </ | ||
directory/run_a_command_upon_files_or_directories_changes.1611624659.txt.gz · Last modified: 2021/01/26 01:30 by peter