Help with script to display space usage

Hi all,

I am looking for help with a script for displaying the space available from a df - h command for / (root).
The problem is: If it is below 700 MB I have jobs that are failing... Is there a way I can do a calculation? If it above 700 MB it is good, if it is below 700 MB it will fail. Any help would be appreciated.

thanks,
Gartie

How far have you come?

---------- Post updated at 18:25 ---------- Previous update was at 17:59 ----------

Howsoever, try

df --output=avail / | { read AV; read AV; [ $AV -gt 700000 ] && echo good || echo bad; }

This one asumes that exactly 700 MB is "bad".

1 Like

Hi Rudic,

I have not gone far at all... I have just started on the script, and it is failing.
I am trying to get the script to read that anything in / below 700 MB is going to fail..

thanks

gartie

df  >temp
while read a b c d e f
do
if [ "$f" = "/" ]
then
    if [ $d -gt 704000 ]
    then
    echo "OK"
    fi
fi
done <temp

It's easier to not use the -h option on df, just remember that the free space is in 1k blocks.

1 Like

The default unit on POSIX conforming systems is 512-byte blocks; not 1k. And, you can make it a little bit faster by just processing root. If you change the 1st line of the script above to:

df -k / > temp

and the rest of the script should be OK.

1 Like

df -kP is most portable IMHO.?

df -kP / |
{
read header
read a b c d e f
if [ $d -gt 704000 ]
then
  echo "OK"
else
  echo "NOT ok"
fi
}
1 Like