我用过这脚本来获取我的大部分代码。我试图编辑它,使代码即使在文件上卡住时也能持续运行。原始 dataanalysis.sh 脚本的情况是,一些文件需要很长时间(2-3 天)才能在 xfoil 中运行,或者它只是冻结。这就是
timeout 1s xfoil $file < xfoil.com
进来。我希望它停止 xfoil 运行并转到下一个文件。我遇到的问题在于 if 循环:
if [ $? = 124 ]; then
xargs mv -t $file < /Failed/$file
it failed
fi
这应该将有问题的文件移动到失败文件夹,以便我可以轻松查看并修复它们。我之前设置了调试,它确实告诉我哪些文件失败了,所以我认为 if 语句确实被执行了,但文件从未移动。我已经研究过这个问题,但目前我迷茫了。请帮忙。
#!/bin/sh
bash -x ./script.sh
exec 5> debug_output.txt
BASH_XTRACEFD="5"
PS4='$lineno: '
cd ./airfoils
mkdir Failed
echo "failed airfoils" > failed.dat
#Then we loop over each file in the working directory whose name ends with .dat
for file in ./*.dat
do
#we write commands to a text file called xfoil.com, this first line overwrite the file and the subsequent lines append to it
echo "pane" > xfoil.com
echo "oper" >> xfoil.com
echo "visc 6.5e5" >> xfoil.com
echo "pacc" >> xfoil.com
#this is the only real dynamic line which we need
echo $file'.analysis' >> xfoil.com
echo "" >> xfoil.com
echo "aseq 0 14 1.0" >> xfoil.com
echo "pacc" >> xfoil.com
echo "" >> xfoil.com
echo "quit" >> xfoil.com
set -x
#we then run xfoil with its STDIN hooked up to the text file where we just wrote the commands to
echo $file
timeout 1s xfoil $file < xfoil.com
if [ $? = 124 ]; then
xargs mv -t $file < /Failed/$file
it failed
fi
#finally we delete the dat file as we have created the polar
set +x
rm $file
done
这是整个脚本
我运行它
bash data.sh