简体   繁体   中英

Ubuntu iNotify multiple folder

I have written a short bash script that sets-up iNotify for several folders, and then calls a Python script to upload the text from the created files to a webservice. The process works fine for the first folder in the list, but the create event does not seem to be firing for the others. I'm assuming I've structured my script in correctly. Any ideas? The code is basically:

#!/bin/bash
inotifywait -m --format '%w%f' -e create /Folder1 | while read FILE
do
    echo $FILE
    # upload file
    python /Scripts/UploadFileContents.py 'PAUR' $FILE
done
inotifywait -m --format '%w%f' -e create /Folder2 | while read FILE
do
    echo $FILE
    # upload file
    python /Scripts/UploadFileContents.py 'RACH' $FILE
done
inotifywait -m --format '%w%f' -e create /Folder3 | while read FILE
do
    echo $FILE
    # upload file
    python /Scripts/UploadFileContents.py 'CDR' $FILE
done
inotifywait -m --format '%w%f' -e create /Folder4 | while read FILE
do
    echo $FILE
    # upload file
    python /Scripts/UploadFileContents.py 'CHR' $FILE
done
inotifywait -m --format '%w%f' -e create /Folder5 | while read FILE
do
    echo $FILE
    # upload file
    python /Scripts/UploadFileContents.py 'PRMS' $FILE
done

Thanks in advance for any assistance.

您必须在inotifywait中启动inotifywait脚本,因为它们将阻塞,直到出现更改

Your first while loop never ends. inotifywait -m is a command that runs forever.

On top of that inotifywait itself is blocking, so breaking all them out to one loop and removing the m flag will not help you either.

The simplest solution for you would be to break them out to multiple scripts.

Or more ideal would be to setup a single script that accepts a few parameters since most of the logic is repeated.

You could replace /Folder1 with $1 and your second variable with $2 Then call your script passing the folder you want to watch.

./watch.sh /Folder1 PAUR &
./watch.sh /Folder2 RACH &

You could make a second script that calls the first script with all your folders you want to watch, to run one script per folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM