What's wrong with this while loop?

function get_tablespace()
{
        ## Get the current size of the tablespace
        size=`su -l oracle -c 'db-control report' |egrep "DATA_TBS" | awk '{print $5}'|tr -d '%'`
         ## Loop through until the size is 82 or less
        count=0
        while [ $size > 82 ] && [ $count < 3 ]
        do
                # For safty, lets not run this more than 3 times
                count=expr count + 1
                `su -l oracle -c 'db-control extend DATA_TBS'`
                report "Increased tablespace size"
                size=`su -l oracle -c 'db-control report' |egrep "DATA_TBS" | awk '{print $5}'|tr -d '%'`
        done
        report "Tablespace is 90 or below: $size $count"
}

Assume $size ends up being 83, the output I get is:

script.sh: line 34: 3: No such file or directory

Line 34 is:
while [ $size > 82 ] && [ $count < 3 ]

Try:

while [[ $size -gt 82 && $count -lt 3 ]]

hth

or

while [ $size -gt 82 ] && [ $count -lt 3 ]

< and > are redirection symbols, even within [ ] . (And within [[ ]] they have a different meaning.)
BTW the > 82 has created a file named 82 - have a look!

1 Like