Link to home
Start Free TrialLog in
Avatar of jhawklyn
jhawklynFlag for United States of America

asked on

Howto store available drive space to a variable for script evaluation

Question:  How can I capture available diskspace information in a script and depending on the value perform actions?

Ideally I'd like a working example of the following pseudo-code:

Set AvailSpace = awk/sed/parse and store to var number
if $AvailSpace > 333800 then
  echo OK
else
  echo abort
endif

Some jobs are failing due to insufficient drivespace.  
This is an old process running on an old box with operating system of:

SunOS Release 4.1.3

I've got a partial clue on how to manually see the value:

JoeUser/usr/local% df | tail -1
/dev/sd2a             963662  581656  333823    64%    /work

I'm just not sure how to assign the value '333823' to a variable for
comparison.

Any thoughts would be appreciated.
Thanks!
Avatar of yuzh
yuzh

In your script you can do: (asume that you are using sh/ksh)


FREESPACE=`df -k | grep device-name | awk '{print $4}'`

   if you want to use device-name a command line arg, using $1 instead of the device-name.

   Cheers!

======
yuzh
ASKER CERTIFIED SOLUTION
Avatar of yuzh
yuzh

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jhawklyn

ASKER

Thanks!  Exactly what I was looking for.   Now I know a little more about awk.   Should help in some other areas.