title: Bash script hangs
body: <p>I have the code below. Basically this code will <code>ls -tr $FROM_DIRECTORY</code> then redirect the output to <code>/tmp/msc.load.tmp</code>. After this a <code>for</code> loop will execute and move the first 3000 files to another directory. The code is working fine but sometimes it will hang. I have no idea why it hangs. Anyone know what is the problem of the script?</p>
  
  <pre><code>ls -tr $FROM_DIRECTORY &gt; /tmp/msc.load.tmp
  echo "$sysdate -- Listing Diretory " &gt;&gt;$LOGFILE
  # From the file list, get the 3000 from the top to move. Skip the remaining files in the list 
  # in this iteration. 
  # Version 1.1 - List the files from the temporary file.  
  for file in $(cat /tmp/msc.load.tmp | grep 'MSCERC.*' | head -3000 )
  do 
     mv $FROM_DIRECTORY/$file $DESTINATION_DIRECTORY
  done
  echo "$sysdate -- End of Script " &gt;&gt;$LOGFILE
  exit 0
  # End of script.
  </code></pre>