更新时间:2023-12-05 20:05:34
叶氏,尝试发现。
另外,如果你没有意识到这一点,设置-x命令是在这样的情况有价值。我的方法是设定-x添加到脚本的顶部,然后重定向到一个文件输出运行。无论捕获标准输出和标准误差
./ script.sh> output.txt的2>&安培; 1
如果你愿意,你可以尾部-f在另一个窗口output.txt的监测进展情况。
设置-x回声命令运行并重定向放命令和输出到cronological秩序。
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.
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 cronological order.