0

So I have an until loop and then I once the conditions of the until loop is satisfied I want the loop to stop and continue down the command line. I submit a handful of jobs using PBS (also written into the script). The .com files are the input and the .log are the output. Currently, it seems that there is something problematic with calling the number of each files equal to one another and thus ending the loop.

$direct is set to the working directory

I know this from several observations:

1) The sleep process is still running when I check it on the supercomputer

2) All of the jobs have finished when I check the queue

3) Further on in the script I ask it to send an email and this doesn't happen

This is my first time working with an until loop and the sleep command, so I am wondering if I got something wrong in the syntax. If I can't solve this until loop, I could theoretically do the same thing with an if/then loop, but from what I've looked at, the until loop should be more efficient.

This is the sliver of the code I am writing that is causing me problems. The completion of the jobs to generate the .log files can take over an hour, so I don't need a short sleep time.

COM=$(find $direct -maxdepth 1 -type f -name "*.com" -printf x | wc -c)
log=$(find $direct -maxdepth 1 -type f -name "*.log" -printf x | wc -c)

until [[ $COM = $log ]];
do 
    sleep 10 #wait 10 seconds between checking values
done 

pattern="*.out"
files=( $pattern )
grep "Isotropic" "${files[0]}" |tr -s ' ' | cut -d " " -f2 > 001.anmr
grep "Isotropic" "${files[0]}" |tr -s ' ' | cut -d " " -f3 > 000.anmr

1 Answers1

1

The "until" expression does not repeat the find commands. Rather, it compares the previously computed values of $COM and $log. It sounds like you want to run the find commands on each pass through the loop. I made a few tweaks to arrive at this demo script:

#!/usr/bin/env bash
set -x   # remove this debugging setting
direct=${1:?Please provide a directory}

COM="find $direct -maxdepth 1 -type f -name *.com"
log="find $direct -maxdepth 1 -type f -name *.log"

until [[ $($COM | wc -l) = $($log | wc -l) ]];
do
    sleep 10 #wait 10 seconds between checking values
done

echo DONE
Eric Bolinger
  • 2,722
  • 1
  • 13
  • 22
  • Will this keep it so that it only counts the number of .com and .log files in the exact folder that direct is set to? later in the script several other folders are created and I don't want it to count the .com and .log files in those folders. – Pyrodancer123 Aug 15 '19 at 18:35
  • Sure @Pyrodancer123, I restored the `-maxdepth` argument and require the directory parameter. – Eric Bolinger Aug 15 '19 at 18:49