[ale] Bash scripting question #2

Dow Hurst Dow.Hurst at mindspring.com
Thu Feb 17 22:57:28 EST 2005


So the || in the do loop says to only execute the echo if the test of 
the link being a file that exists returns true?

I have a script that I'd like to have watch 10 files and when the last 
one is removed, then move on to the next command in the script.  I 
initially tried testing for the existence of all 10 files but I know I 
have the syntax wrong.

Here is the while loop that failed:

## Wait and watch for locks to disappear
cd $CWD
LK=biased.lck
TERM="BatchMin normal termination"

while :
do

    if   [ -f $CWD/00/biased/$LK || $CWD/01/biased/$LK || 
$CWD/02/biased/$LK || $CWD/03/biased/$LK || $CWD/04/biased/$LK \
           || $CWD/05/biased/$LK || $CWD/06/biased/$LK || 
$CWD/07/biased/$LK || $CWD/08/biased/$LK || $CWD/09/biased/$LK ]
         then sleep 900
    elif [ "$TERM"="`grep 'BatchMin normal termination' 
$CWD/09/biased/biased.log`" ]
         then echo "09 biased terminated normally"
         break
    else echo "09 biased failed!"
         sleep 3600
    fi
done

sync
sleep 10

echo "Finished biased runs "; date
#End Section that didn't work###################



Here is the while loop that watches the last job only, however, it can 
run longer than the next to the last job in certain cases.  So this 
isn't a robust solution:
echo "Starting biased ";date

cd $CWD/00/biased
./bminv < ./biased.com > ./biased.log &
echo "Biased run 00 PID = $!"
sleep 300

cd $CWD/01/biased
./bminv < ./biased.com > ./biased.log &
echo "Biased run 01 PID = $!"
sleep 300

cd $CWD/02/biased
./bminv < ./biased.com > ./biased.log &
echo "Biased run 02 PID = $!"
sleep 300

cd $CWD/03/biased
./bminv < ./biased.com > ./biased.log &
echo "Biased run 03 PID = $!"
sleep 300

cd $CWD/04/biased
./bminv < ./biased.com > ./biased.log &
echo "Biased run 04 PID = $!"
sleep 300

cd $CWD/05/biased
./bminv < ./biased.com > ./biased.log &
echo "Biased run 05 PID = $!"
sleep 300

cd $CWD/06/biased
./bminv < ./biased.com > ./biased.log &
echo "Biased run 06 PID = $!"
sleep 300

cd $CWD/07/biased
./bminv < ./biased.com > ./biased.log &
echo "Biased run 07 PID = $!"
sleep 300

cd $CWD/08/biased
./bminv < ./biased.com > ./biased.log &
echo "Biased run 08 PID = $!"
sleep 300

cd $CWD/09/biased
./bminv < ./biased.com > ./biased.log &
echo "Biased run 09 PID = $!"
sleep 5

## Wait and watch for locks to disappear
cd $CWD
LK=biased.lck
TERM="BatchMin normal termination"

while :
do

    if   [ -f  $CWD/09/biased/$LK ]
         then echo "Sleeping while waiting on biased ";date;sleep 900
    elif [ "$TERM"="`grep 'BatchMin normal termination' 
$CWD/09/biased/biased.log`" ]
         then echo "09 biased terminated normally"
         break
    else echo "09 biased failed!"
         sleep 3600
    fi
done

sync
sleep 5

echo "Finished biased runs "; date
#END of section that works######################


What is wrong with the original while loop file test?  Thanks for the help,
Dow


Geoffrey wrote:

> John Mills wrote:
>
>> ALErs -
>>
>> Should be simple, but I don't see it:
>>
>> I have a directory with softlinks to a number of files that no longer 
>> exist, along with links to files that _do_ exist.
>>
>> How can I selectively list those links which are _not_ satisfied, so 
>> I can remove them at one go, while ignoring those for which the 
>> linked files still exist?
>
>
> rm $(for fn in *; do
> test -f $fn || echo $fn
> done)
>



More information about the Ale mailing list