I have the code below. Basically this code will ls -tr $FROM_DIRECTORY
then redirect the output to /tmp/msc.load.tmp
. After this a for
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?
ls -tr $FROM_DIRECTORY > /tmp/msc.load.tmp
echo "$sysdate -- Listing Diretory " >>$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 " >>$LOGFILE
exit 0
# End of script.