title: Processing data with inotify-tools as a daemon
body: <p>I have a bash script that processes some data using inotify-tools to know when certain events took place on the filesystem. It works fine if run in the bash console, but when I try to run it as a daemon it fails. I think the reason is the fact that all the output from the <code>inotifywait</code> command call goes to a file, thus, the part after <code>| while</code> doesn't get called anymore. How can I fix that? Here is my script.</p>
  
  <pre><code>#!/bin/bash
  
  inotifywait -d -r \
  -o /dev/null \
  -e close_write \
  --exclude "^[\.+]|cgi-bin|recycle_bin" \
  --format "%w:%&amp;e:%f" \
  $1|
  while IFS=':' read directory event file
  do
  
      #doing my thing
  
  done
  </code></pre>
  
  <p>So, <code>-d</code> tells <code>inotifywait</code> to run as daemon, <code>-r</code> to do it recursively and <code>-o</code> is the file in which to save the output. In my case the file is <code>/dev/null</code> because I don't really need the output except for processing the part after the command (<code>| while...</code>)</p>