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