bash script which watches directory for new files
<p>It's important to note immediately there are many variations of the 'script to watch a directory' I realize inotify-tools would be ideal however this particular script is being used to monitor a vboxsf filesystem which unfortunately doesn't forward filesystem notifications. This script is a hack to refresh a file so a separate running daemon will notice it. </p>

<p>The script below is a compromise. I spent a long time dealing with various issues </p>

<ol>
<li>the correct <code>find</code> args</li>
<li>the <code>find</code> path and</li>
<li>the timing for touching the found file.</li>
</ol>

<p>The objective is to identify the new file, touch it so the separate running daemon notices it and subsequently processes it. The problem is, well, it gobbles cpu and presumably from the find. I'd like help in finding a more efficient way of doing this. </p>

<p>Although not necessary, but to fully test, one would need a mounted vboxsf filesystem with inotifywait running like so <code>inotifywait -m /watches/watchdir -e attrib</code> </p>

<p>File creation on the host side will not result in an ATTRIB notification on the guest side until the file is somehow refreshed -- in which case this hack uses '<code>touch</code>'</p>

<pre><code>thedir=/watches/watchdir

touch_me() {
    if [ "${newbie}" ]; then
 #  echo "got this: ${newbie}"
    touch -d '-120 seconds' "${newbie}"
    fi
}

while true
do
    newbie=`find $thedir/* -type f -mmin 0.1 2&gt;/dev/null`
    touch_me
done
</code></pre>