title: Bash script to monitor multiple paths and end email notification when a new file is added
body: <p>I have written a script to monitor 2 directories and to end an email notification if a new file gets added here, but it seems to be monitoring only the 1st directory and not the second (i don't get a notification when I add something to the 2nd directory), can anyone help me fix this?
  script:</p>
  <pre><code>#!/bin/bash
  
  monitor_dir=/path1/UnSent
  monitor_dir1=/path2/failed
  
  email=email1.com
  email2=email2.com
  
  
  files=$(find &quot;$monitor_dir&quot; -maxdepth 1 | sort)
  IFS=$'\n'
  
  while true
  do
    sleep 5s
  
    newfiles=$(find &quot;$monitor_dir&quot; -maxdepth 1 | sort)
    added=$(comm -13 &lt;(echo &quot;$files&quot;) &lt;(echo &quot;$newfiles&quot;))
  
    [ &quot;$added&quot; != &quot;&quot; ] &amp;&amp;
      find $added -maxdepth 1 -printf '%Tc\t%s\t%p\n' |
      mail -s &quot;your file sent to UnSent&quot; &quot;$email&quot; 
  
    files=&quot;$newfiles&quot; 
  done
  
  files1=$(find &quot;$monitor_dir1&quot; -maxdepth 1 | sort)
  IFS=$'\n'
  
  while true
  do
    sleep 5s
  
    newfiles1=$(find &quot;$monitor_dir1&quot; -maxdepth 1 | sort)
    added=$(comm -13 &lt;(echo &quot;$files1&quot;) &lt;(echo &quot;$newfiles1&quot;))
  
    [ &quot;$added&quot; != &quot;&quot; ] &amp;&amp;
      find $added -maxdepth 1 -printf '%Tc\t%s\t%p\n' |
      mail -s &quot;your file sent to failed&quot; &quot;$email2&quot; 
  
    files1=&quot;$newfiles1&quot; 
  done
  </code></pre>