when i want to check the disk space.. if any disk reach more than or equal to 50% i want to print NOT OK. if its less than 50% i need to print "OK"
pls check the below code is correct... its not working.. kindly suggest me
code :
d=`df -k |awk '{print $5}' | egrep "[5-9][0-9]" | cut -c-2`
if [ "$d" == "50" ]
then
echo "DISK SPACE STATUS :NOT OK" >> /backup/stats/healthcheck/SCP1_BLU_HCsummary_$dt.txt
else
echo "DISK SPACE STATUS :OK" >> /backup/stats/healthcheck/SCP1_BLU_HCsummary_$dt.txt
fi
Thanks kevin... its working yar..... thank u so much.. but its showing like this..
bash-3.00$ df -k | awk ' { p=substr($5,1,index($5,"%")-1); if(p+0>=50) print "NOT OK"; else print "OK" }'
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
NOT OK
NOT OK
OK
NOT OK
So you want to know which partition is "NOT OK", right?
df -k | awk ' { p=substr($5,1,index($5,"%")-1); if(p+0>=50) print $NF " is NOT OK, over " p "% of its available space is used."; else print $NF " is OK." }'
ex:
/oracle is NOT OK, over 80% of its available space is used.
/export/home is NOT OK, over 76% of its available space is used.
/opt/product is NOT OK, over 87% of its available space is used
For doubt 1, I don't quite understand what you mean. In my script I stripped "%" for the 5th column, and compare the number I get with 50, equals to or above it, it just works like a charm. why don't you think it would discovery that if the disk is used 51%?
For doubt 2, I am still confused.
I didn't have a Solaris system to test my script, so I just copied the input sample Steve posted, it all worked before I posted each response.
d=`df -k |awk '{print $5}' | egrep "[5-9][0-9]" | cut -c-2`
if [ "$d" == "50" ]
then
echo "DISK SPACE STATUS :NOT OK" >> /backup/stats/healthcheck/SCP1_BLU_HCsummary_$dt.txt
else
echo "DISK SPACE STATUS :OK" >> /backup/stats/healthcheck/SCP1_BLU_HCsummary_$dt.txt
fi
The line: "if [ "$d" == "50" ]" is true only when the diskspace is exactly 50 % and then you get "DISK NOT OK".
When the disk is more (or less) then 50 %, you will get "DISK OK".