How to get recursive directory path using inotify-tools in terminal

2.8k views Asked by At

I'm using inotify-tools where i want a notification of file which has been created in recursive directories

Till here i'm succesfull

Now i want to get directory path where a file is been created/dumped in the recursive folders

for e.g abc.txt file is dumped in data/test folder

i want the path to be data/test/abc.txt

Below is the code im using in .sh file

inotifywait -m -r --format '%f' -e modify -e move -e create -e delete /var/www/cloud/data | while read LINE; 
do 
    php /var/www/cloud/scannner/watcher.php; 
done

Kindly please help me to get the path of a dumped file in recursive directories

Cheers

1

There are 1 answers

2
user000001 On BEST ANSWER

Use the %w modifier:

inotifywait -m -r --format '%w%f' .......

To pass the output of inotifywait as an argument to a php script, which will read it for the argv variable you could do this:

inotifywait -m -r --format '%w%f' ....... | while read -r line
do 
    php script.php "$line"
done

Otherwise, if you want the php script to read the output of inotifywait from the standard input, then you can just pipe to your script:

inotifywait -m -r --format '%w%f' ....... | php script.php