Search code examples
bashinotifywait

Capture output of inotifywait in bash


How can i capture the output of inotifywait in this instance, it is driving me crazy.

Here is my code:

 while inotifywait -q -e  create,delete --format '%T %:e "%f"' --timefmt '%d/%m/%y %H:%M'  "$DIR"
    do
       echo -e "$line" >> /mnt/pidrive1/Digital_Signage/log/"$hostname"_sync.log
       echo -e "Folder contents:" $file_number "files in total: " $folder_list  >> /mnt/pidrive1/Digital_Signage/log/"$hostname"_sync.log
    done

Solution

  • A much simpler way to achieve what you want would be:

    while inotifywait <whaveter> >> sync.log
    do
       # Nothing
    done
    

    If you need to do extra stuff to your output you can say:

    while out=$(inotifywait <whaveter>)
    do
        # Stuff
        # Just use $out normally
    done