Shell script randomly fails to execute file operations commands

458 views Asked by At

I'm having a bit of trouble running this script. Every now and then, it will fail to execute a mv command or rm command referenced below. Then the next iteration will feel the full repercussions of that failure. Why is this happening, and how do I control for it? For reference, the syntax phyml -i $f [parameters] outputs the files $f_phyml_tree.txt and $f_phyml_stats.txt into the same directory as $f. I want to get both these files out of that directory while saving the tree somewhere else.

ber="_phyml_tree.txt"
for f in ~/randseqs/aa/*.txt;
do
    echo $f
    fpath=`echo $f | cut -d'/' -f 6`
    if [ ! -f /home/mcb3421_10/phymlout/aa/$fpath$ber ] || [ ! -f /home/mcb3421_10/phymltimer/aa/$fpath ]; then
        phyml -i $f -d aa -b 0 -m Blosum62 > ~/blown.txt
        grep "Time used" < ~/blown.txt > ~/phymltimer/aa/$fpath
        mv /home/mcb3421_10/randseqs/aa/*$ber phymlout/aa
        if [ ! -f /home/mcb3421_10/phymlout/aa/$fpath$ber ]; then
            echo $f failed to write, check the logfile /home/mcb3421_10/phymllogs/aa/$fpath
        fi
        rm ~/randseqs/aa/*_stat*
        mv ~/blown.txt ~/phymllogs/aa/$fpath
    fi
done
for f in ~/randseqs/nuc/*.txt;
do
    echo $f
    fpath=`echo $f | cut -d'/' -f 6`
    if [ ! -f /home/mcb3421_10/phymlout/nuc/$fpath$ber ] || [ ! -f /home/mcb3421_10/phymltimer/nuc/$fpath ]; then
        phyml -i $f -d nt -b 0 -m HKY85 > ~/blown.txt
        grep "Time used" < ~/blown.txt > ~/phymltimer/nuc/$fpath
        mv /home/mcb3421_10/randseqs/nuc/*$ber phymlout/nuc
        if [ ! -f /home/mcb3421_10/phymlout/nuc/$fpath$ber ]; then
            echo $f failed to write, check the logfile /home/mcb3421_10/phymllogs/nuc/$fpath
        fi
        rm ~/randseqs/nuc/*_stat*
        mv ~/blown.txt ~/phymllogs/nuc/$fpath
    fi
done
0

There are 0 answers