title: How to handle error/exception in shell script?
body: <p>Below is my script that I am executing in the bash. And it works fine.</p>
  
  <pre><code>fileexist=0
  for i in $( ls /data/read-only/clv/daily/Finished-HADOOP_EXPORT_&amp;processDate#.done); do
    mv /data/read-only/clv/daily/Finished-HADOOP_EXPORT_&amp;processDate#.done /data/read-only/clv/daily/archieve-wip/
    fileexist=1
  done
  </code></pre>
  
  <p><strong>Problem Statement:-</strong></p>
  
  <p>In my above shell script which has to be run daily using <code>cron job</code>, I don't have any <code>error/exception handling mechanism</code>. Suppose if anything gets wrong then I don't know what's has happened? </p>
  
  <p>As after the above script is executed, there are <code>some other scripts that will be dependent on the data provided by above script</code>, so I always get's complaint from the other people who are depending on my script data that something wrong has happened. </p>
  
  <p>So is there any way I can <code>get notified if anything wrong has happened</code> in my script? Suppose if the <code>cluster is having some maintenance</code> and at that time I am running my script, so definitely it will be failing for sure, so can I be notified if my above scripts failed, so that I will be sure something wrong has happened.</p>
  
  <p>Hope my question is clear enough.</p>
  
  <p>Any thoughts will be appreciated.</p>