Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash脚本挂起_Bash_Unix_Scripting - Fatal编程技术网

Bash脚本挂起

Bash脚本挂起,bash,unix,scripting,Bash,Unix,Scripting,我有下面的代码。基本上,这段代码将ls-tr$从_目录,然后将输出重定向到/tmp/msc.load.tmp。在此之后,将执行for循环,并将前3000个文件移动到另一个目录。代码运行良好,但有时会挂起。我不知道它为什么挂着。有人知道剧本有什么问题吗 ls -tr $FROM_DIRECTORY > /tmp/msc.load.tmp echo "$sysdate -- Listing Diretory " >>$LOGFILE # From the file list, ge

我有下面的代码。基本上,这段代码将
ls-tr$从_目录
,然后将输出重定向到
/tmp/msc.load.tmp
。在此之后,将执行
for
循环,并将前3000个文件移动到另一个目录。代码运行良好,但有时会挂起。我不知道它为什么挂着。有人知道剧本有什么问题吗

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.
是的,试试看

另外,如果您没有意识到,set-x命令在这种情况下非常有用。我的方法是将set-x添加到脚本的顶部,然后在输出重定向到文件的情况下运行它。捕获标准输出和标准错误

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

如果需要,可以在另一个窗口中跟踪-f output.txt以监视进度


Set-x会回显命令的运行,重定向会将命令和输出按权变顺序排列。

最好只使用
find
命令,而不使用中间文件。使用“bash-x”运行它,这样您就可以看到它在哪里以及可能为什么是unix的新成员。我可以知道如何在脚本中添加-x吗?gv可以举个例子吗?
cat
head
和regex通配符都是不必要的。另外,
grep-m3000 MSCERC/tmp/msc.load.tmp |同时读取-r文件;执行
。。。最后,哪一部分保证stdout和stderr按时间顺序排列?按时间顺序写行。与尝试从控制台关联stderr和从重定向关联stdout而不使用stderr部分不同,但是仍然不能保证它们会同步写入。我的意思是,是的,这比让它们去两个不同的目的地要好,但如果溪流被淹没,它们就不一定会按顺序输出。但是我想提问者必须抓住机会。我是unix新手。我可以知道如何在脚本顶部设置-x吗?gv可以举个例子吗?可以像上面hmontoliu所说的那样使用-x参数调用脚本,或者编辑脚本,并在ls-tr$行上方从_DIRECTORY>/tmp/msc.load.tmp输入set-x