1

I have Used this script to get majority of my code. I am trying to edit it where the code continually runs even when getting stuck on a file. What happens with original dataanalysis.sh script is that some files takes really long time, 2-3 days, to run in xfoil or it just freezes. Thats where

 timeout 1s xfoil $file < xfoil.com

comes in. I want this stop xfoil from running and go to next file. Where I am having problems is with the if loop:

if [ $? = 124 ]; then
                xargs mv -t $file < /Failed/$file
                it failed
fi

This is supposed to move the troublesome file to Failed folder so that I can easily view and possibly fix them. I had debug set up before where it did tell me which files failed so I think the if statement does get executed but the file never moves. I have researched this and am lost at this point. Please help.

#!/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

This is the entire script

I ran it as

bash data.sh

4
  • The syntax for moving a file to a target dir is either mv file dir/ or mv -t dir/ file - I don't get how you came up with xargs mv -t $file < /Failed/$file. Also the exit status test should probably use -eq not = i.e. [ $? -eq 124 ] (= is for string comparisons) Jan 22, 2017 at 22:24
  • @steeldriver I have tried that, I came up with it here. I have tried same advise before also. After I have found this latest solution I came here. I tried many terms for this and came empty. --- the statement now:--- if [ $? -eq 124 ]; then--- mv file Failed/--- it failed--- fi--- Jan 23, 2017 at 0:43
  • it failed isn't a valid command - did you perhaps mean to write echo "it failed"? Also the directory Failed must exist for this to work Jan 23, 2017 at 0:49
  • The Directory does exist and have removed "it failed" line. It still doesnt move the file Jan 24, 2017 at 0:46

0

You must log in to answer this question.

Browse other questions tagged .