How to track the sequences in the file changes with Inotifywait

255 Views Asked by At

Currently I am monitoring the files by using above code, it works as expected. Basically I am monitoring the opened text files and executing commands.

inotifywait -m -q /home/testDir -e open |
    while read path action file; do

        if [[ "$file" =~ .*txt$ ]]; then
      #  execute command
        fi
    done

I wonder, how can I monitor the sequences of the inotifywait events and execute command.

For example, how can I execute a command or echo something when there is a open,access,close_nowrite event in the directory?

/home/TestDir OPEN test.txt
/home/TestDir ACCESS test.txt
/home/TestDIr CLOSE_NOWRITE,CLOSE test.txt
0

There are 0 best solutions below