need with script which i am doing to print the status

df -h | awk '{if ($5 < 86%) {"   " print 'status ok'}  else {print 'Highdisk usage'}}

i am trying to check if th disk usage is above 86% please let me know what the problem.

you should get rid of % symbol, to perform maths comparision.

if i get rid of the % symbol shd i put it as a field seperator.in the awk

df -h | awk 'sub("%","",$5) { if ( $5 > 86 ) { print $NF,"is over 86%" } else { print $NF,"is OK" } }'

its give me this error while running it

"a1.sh" 4 lines, 103 characters
hostname> ./a1.sh
+ + awkdf  {if ($5 < 86) {"   " print status -hok}  else {print Highdisk
 usage}}

awk: syntax error  Context is:
>>>     {if ($5 < 86) {"   " print      <<<

Hi,
Try this out -----

Write a script

#!/bin/sh
output=`df -h | awk '{ print $5}'`
per=$(echo $output |  cut -d'%' -f1 )
if [ $per -ge 86 ]; then
echo "HighDisk Usage"
else
echo "Status OK"
fi

thanks

Hi Arch12

Your original one was almost correct. Use the int function:

df -h | awk '{if (int($5) < 86) { print "status ok"} else {print "Highdisk usage"}}'

OR
this will give you only high usage processes:

df -h | awk '(int($5) >=86)'

Guru.

./b1.sh: syntax error at line 4: `per=$' unexpected

I use this script for the same purpose.

#!/bin/sh
df -P | awk '{if (int(substr($5,1,length($5)-1)) >= 90) { print $1 " mounted on " $6 " is " $5 " full"}}' > /tmp/fsdetails.txt
size=`/bin/ls -l  /tmp/fsdetails.txt | awk '{print $5}'`
if [ "$size" -gt "0" ]; then
mailx -s "File system alert on `hostname`" xtz@gmail.com < /tmp/fsdetails.txt
rm -f /tmp/fsdetails.txt
exit 0;
fi
rm -f /tmp/fsdetails.txt