need help writing a script to check disk quotas

I'm not too great at scripting yet, i've written a couple of basic scripts hacked together from others i've seen working and ideas i've picked up here and there...but anyways....

I need to be able to check disk quota and determine how much free space i have. My other scripts always used df but on the system i'm on now i need to make them work with quota.

anyways, i figured out that a user can call quota and get a reading like this:
Code:
Disk quotas for user rpuser11 (uid 1004): 
     Filesystem   usage   quota   limit   grace   files   quota   limit   grace
          /home      30       0 78643200              15       0       0


what's the best way to figure out the free space....i know it would be to somehow take the usage number and subtract it from the limit number but i do not know the best way to do this..

i know i can use tail -1 to get it down to just
Code:
/home      30       0 78643200              15       0       0
but what i do from there....


edit, i just figured out awk is what i'm looking for.
 
ok, does this look right guys?
Code:
quota | tail -1 | awk '{print $4 - $2}'

and does

Code:
quota | tail -1 | awk '{print $4/($4 - $2)}'

look right if i want to know the percentage?

edit:

actually, i'm thinking this would be the percentage....but i'm not sure if i have it 100% right

Code:
quota | tail -1 | awk '{print ($2*100)/$4}'
 
$ quota | tail -1 | awk '{ print 100 * $2 / $4 }'
This will show the used space in percentage float numbers. (used/total)

$ quota | tail -1 | awk '{ print 100 * ($4 - $2) / $4 }'
This will show the free space in percentage float numbers. (free/total)
 
To make it look more neat you can convert them to integers before displaying:
$ quota | tail -1 | awk '{ print int(100 * $2 / $4) "%" }'
or
$ quota | tail -1 | awk '{ print int(100 * ($4 - $2) / $4) "%" }'

Sorry about the double post. I'm a new user so I can't edit :p
 
Back
Top