printing positional charaters in a loop

#!/bin/bash
usep=`df -hT | awk '{ print $5 }'`
for (1=1,1<8,i++)
output=`echo $usep | awk '{ print $i }'| cut -d'%' -f1`
echo $output
if [ $output -gt 10 ]
then
echo "critical value"

i need to echo critical value if disk usage pecentage xceeds 10

and i am face problem in position marked red here i am trying to print i where i represent postional parameter from 1to8 but i am not able to print
but i am able to get output if i am directly useing postional parameters instead of i ....

please suggest accordingly

Thanks in Advance

Jos

$6 is the "Use %" column in my system's output.

df -hT | awk '{x=$6; sub(/%/,"",x); if (x > 10){print $0,"\t <= critical value"}}'

tyler_durden

Not tested, -T don't work on my system.

df -hT | awk 'int($5) > 10{print $0,"\t <= critical value"}'

It works, $5 just needs to changed to $6 :

df -hT | awk 'int($6) > 10 {print $0,"\t <= critical value"}'

Although I don't see why disk usage of more than 10% should be considered critical. Perhaps the OP means 90% ?

I think we need to know which Operating System and version. There is much variety in the "df" command.
For this purpose, sample input (from df -Ht) and sample expected output would do.

If you just want to filter out a positional part of the output you do not need awk at all:

read var1 var2 var3 ...

will break down the output and assign word 1 to var1, word 2 to var2 and so on. If there are more words than variables the last variable will get the remainder of the line. You can use a dummy variable over and over again to filter out what you are not interested in:

example (filter out the size only):

df -hT | tail -1 | read junk junk fssize junk

Your code could be simplified to (adjust the number of "junk"s to adapt to your systems output):

df -hT | while read fs_name junk junk junk junk fs_used_percent junk ; do
     if [ $fs_used_percent -gt 10 ] ; then
         echo "Warning: $fs_name usage above threshold"
     fi
done

I hope this helps.

bakunin

Bi bakunin. No offence but the output from many versions of "df -k" contains a "%" sign suffixed to the value. O/P jossgeorge script suggests that this is one of those versions.

This might be. If this is the case one could still strip the trailing percent-sign off the read string before the comparison. This is still faster than to fire off awk to parse a line. I haven't tried to come up with a full-blown solution but only a sketch exemplifying what i tried to explain.

bakunin

Agreed your approach is good and I like the multiple use of the variable "junk" (I didn't know you could do that but I have now tested the idea).

We need real examples from the OP.

Of course you could call the variable any way you like. I habitually call it "junk" because this signifies its content. The technique is one of the leftovers from my REXX experience (i worked on mainframes before "downgrading" to midrange systems), where this is the normal way to do it. In REXX you even have a special variable "." for this, which is "throw-away", so to say.

bakunin