title: Check every half and hour and see whether the if condition is true or not
body: <p>There are two directories, which contains some files. I am working with Hadoop and both of these two directories are Hadoop File System.</p>
  
  <p>First Location of Directory-</p>
  
  <pre><code>/sys/edw/
  </code></pre>
  
  <p>Second Location of Directory-</p>
  
  <pre><code>/apps/only/
  </code></pre>
  
  <p>I want to see if <code>these two directories</code> has some <code>files or not</code>. If they contains some files, then <code>continue and execute my other shell scripts</code>, but if they do not contain any files, <code>wait for half an hour</code> and then check back again whether the files has arrived in those two directories or not. </p>
  
  <p>If it has arrived then execute other shell scripts but if it is not arrived then wait for half an hour again and keep on checking every half an hour.</p>
  
  <p><strong>Algorithm-</strong></p>
  
  <pre><code>If [ hadoop fs -ls /sys/edw/   AND hadoop fs -ls /apps/only/ ]
  then
  continue executing my other shell scripts
  but if condition is not true
  wait for half an hour and then check again with the if loop and keep on looking every half an hour until the if condition is not true
  </code></pre>
  
  <p>I want to execute this below script only when the above if condition is true.</p>
  
  <pre><code>query.sh
  </code></pre>
  
  <p>Basically I have few scripts that I want to run only  <code>if condition is true</code> otherwise keep on checking <code>every half an hour</code> and see whether the <code>if condition is true or not</code>.</p>
  
  <p>I am runnign <code>SunOS 5.1</code></p>
  
  <p><strong>Updated Code:-</strong></p>
  
  <p>I am trying something like below and file doesn't exist in this directory(/apps/hdmi/20120916), so it should be sleeping for half an hour but instead of sleeping, it goes to execute the other shell scripts which it shouldn't be doing-</p>
  
  <pre><code>while [ ! hadoop fs -ls /apps/hdmi/20120916 ]; do
      sleep 1800
  done
  
  echo "Hello new11"
  pwd
  </code></pre>
  
  <p>Anything wrong I am doing?</p>
  
  <p><strong>Updated One Again:-</strong></p>
  
  <pre><code>while ! hadoop fs -ls /apps/hdmi/20120916 ; do
      sleep 1800
  done
  
  echo "Hello new11"
  pwd
  </code></pre>
  
  <p>I have tried the above one also, but this directory doesn't exist (/apps/hdmi/20120916) and instead of sleeping for half an hour, it goes and print the <code>Hello new11</code> which shouldn't be happening. It should wait for half an hour. Anything else I am missing? I am running <code>SunOS 5.1</code></p>