Ossama
Ossama

Reputation: 2433

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

Upvotes: 2

Views: 2289

Answers (2)

Bobster
Bobster

Reputation: 1

inotifywait -m some_dir |
  while read -r dir action file ; do
    echo "Inotify returned: dir=$dir action=$action file=$file"
  done

Upvotes: 0

cnicutar
cnicutar

Reputation: 182609

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

Upvotes: 3

Related Questions