Hi,
Could someone tell me in this line:
/dev/hda2 12001268 1538572 9843232 14% /
How could i grep so it only shows when the number is from 90% to 100%?
i've tried df -k | grep '/dev/hda2' | cut -c 53-55 | grep '^9' | grep '^100'
but it dosent work.
Thanks in advance
Try this:
df -k | grep '/dev/hda2'| awk '{sub("%","",$5) ; if($5>89) print}'
If you are looking for alerting when the hard disk reaches 90%, then perl is more reliable than checking in this way of GREP, and commands..
This will help you a lot: Perl script to monitor disk space and send an email
df -HP | { while read disk b c d used e
do
used=${used%?}
case "$used" in
[9][0-9]|100)
echo "overload over 90%: $disk, used: $used%"
esac
done
}
I don't get how perl could be "more reliable". Both Perl and the shell/awk results are 100% correct for such a simple task.
that's right. I think he is talking about all those extra greps, which are totally unnecessary.
Go it:
df -k | awk '$1 == "/dev/hda2" {sub("%","",$5) ; if($5>89) print}'
or the simpler if all filesystems are to be tested:
df -k | awk '{sub("%","",$5) ; if($5>89) print}'
thanks guys, it did the job