Table of Contents

Usage

Start ./onfilechange.sh -h to get the help

______________________________________________________________________________

  T R I G G E R    C O M M A N D    O N    A    F I L E C H A N G E
______________________________________________________________________________
                                                                         v1.04

INFO: stat command detected
HELP:
        This script checks the change of a given file and triggers
        a command if it changes

PRAMETERS:
        -c [command]
            command to execute on a file change
        -f [filename(s)]
            filenames to watch; separate multiple files with space and put all in quotes
        -h
            show this help
        -i
            force inotifywait command
        -s
                force stat command (default mode)
        -v
            verbose mode; enable showing debug output
        -w [integer]
            for stat mode: wait time in seconds betweeen each test or on missing file; default: 5 sec

EXAMPLES:
        onfilechange.sh -f /home/me/touchfile.txt -c "ls -l" 
            watch touchfile.txt and make a file listing on change

        onfilechange.sh -f "/home/me/touchfile.txt home/me/touchfile2.txt" -c "ls -l" 
            watch touchfile.txt and touchfile2.txt

        onfilechange.sh -f /home/me/touchfile.txt -s -w 10 -c "echo hello" 
            watch touchfile.txt every 10 sec with stat and show "hello" on a change

Test on command line

To make a test on commandline touch a testfile touch /tmp/mytestfile. The start the script with enabled debugging (-d) in a 2nd terminal:

/usr/local/bin/onfilechange.sh -v -f "/tmp/mytestfile" -c 'echo "hello"'

Each time you touch the testfile in another terminal window it should show “hello”.