title: Executing a bash script upon file creation
body: <p>I am looking write a small bash script to, when launched, watch a directory for any newly created files. If a new file appears, I want its presence to trigger a second script to run. </p>
  
  <p>I see this being used to trigger the compression recently digitized video, and add it to a log of ingested footage.</p>
  
  <p>Currently my code looks like this:</p>
  
  <pre><code>#!/bin/sh
  
  ##VIDSTAT is a global variable coming from a parent script.
  ##proj is the ingestion directory coming from a parent script
  proj=$1
  
  dir="/home/$USER/data/movies/$proj"
  dirlist=$(ls $dir)
  
  
  while { $VIDSTAT -eq 1 }:
  do
      for mov in $dirlist
      do
          if [ "$(( $(date +"%s") - $(stat -c "%Y" $mov) ))" -lt "5" ]
          then
          ~/bin/compressNlog.sh $mov
          fi
      done
  done
  </code></pre>
  
  <p>Is there an easier/cleaner/less memory intensive way to do this? </p>
  
  <p><strong>EDIT</strong> I will be changing the ingestion directory per capture session. I have adjusted the code accordingly</p>