开发者

Bash script hangs

开发者 https://www.devze.com 2023-03-26 16:06 出处:网络
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 direct

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 Sc开发者_开发百科ript " >>$LOGFILE
exit 0
# End of script.


Yeap, try a find.

Also if you're not aware of it, the set -x command is valuable in situations like this. My approach is to add set -x to the top of the script and then run it with output redirected to a file. capturing both standard out and standard error

./script.sh > output.txt 2>&1

If you want you can tail -f output.txt in another window to monitor progress.

set -x echos the commands run and the redirection puts the command and output into chronological order.

0

精彩评论

暂无评论...
验证码 换一张
取 消