Newbie problem

Hi. I'm new to shell script and i have a problem

My code

ssh $i df -h|grep -ve Use | awk '{ if ( substr( $5, 1, length($5) - 1) > 80 )  echo -n "-----\n"$5"   "$6 ; else echo -n "------\nOK!" }' | sort -u

The problem is : for example, if the %Use is ( 78;81 ), the scripts will print both "78" and "OK". I just want to print "78". "OK" is printed only if all the %Use < 80.

The same problem with this :confused::confused::confused:

if [ $j -gt 80 ]
                   then
                         echo $j"%    " $name
                   else
                         echo "\nOK!\n"
                   fi

Can someone help me solve this

Set a flag variable if any FS utilization crosses 80%. In the END rule, print OK if flag is not set:

df -h | awk '
        {
                used = $(NF-1) + 0
                if ( used > 80 )
                {
                        print used "%", $NF
                        flag = 1
                }
        }
        END {
                if ( !flag )
                        print "OK"
        }
'

Try this also:

df | awk        'NR>1   {sub("%","",$5)
                         print $5 "%", $6
                         flag=flag||($5>80)
                        }
                 END    {if (!flag) print"OK"}'

Thanks guys, it works, but just in the second example

I can't do it in the first one because i can't make multiple commands after awk