Using df -h command to show hard drive info

ooshnoo
Valued Contributor

Hello,

Does anyone know how I might utilize the df -h command to create a report on hard drive sizes and how much of each drive is being used?

Possibly an extension attribute???

Thanks!

-- Adam Vadala
Infrastructure Engineer | CareerBuilder
773 353 2870 | adam.vadala@careerbuilder.com

1 ACCEPTED SOLUTION

mm2270
Legendary Contributor III

No problem. As I'm sure you know, to make the above into an Extension Attribute, put in something like the following:

#!/bin/sh

diskUsage=`df -h | awk '/disk0s*/{print $3}' | sed -e 's/[A-Z]/ &/' -e 's/i/B/'`

echo "<result>$diskUsage</result>"

I would consider making it an integer data so you can search on more than/less than values.

View solution in original post

7 REPLIES 7

mm2270
Legendary Contributor III
df -h | awk '/disk0s*/{print $3}' | sed -e 's/[A-Z]/ &/' -e 's/i/B/'

There may be a more efficient way to do this, but the above should output the space used on the boot drive in human readable format, something like "70 GB" for example.
You could also use the percentage used item in Inventory to pull a report on the space used on the boot drives for your Macs. Like:

Advanced Search > Criteria > Storage > Boot Drive Full | more than | 0

Just make sure with the above that you check the Boot Drive Full column in Display Fields so it shows up in the results. Then export it to whatever format works best for you.

But I've never much liked using the % full item since its not always a good indicator.<10% disk space left on a MacBook Air with an older 80 GB SSD is a LOT less than <10% left on a Mac Pro with a 1 TB drive. I'd be concerned about the former, but not so much about the latter.

Awhile back I made an EA that pulled the "Avail" column from df on the boot volume, and made it an integer so I could build groups on a 'less than x' amount value and get emailed when they fell below the threshold.

ooshnoo
Valued Contributor

thank you sir. I was going to use the Boot Drive Full method but the boss wants an average of storage used, as since our drives are of all different sizes that won't work.

I'll try your solution in the AM.

mm2270
Legendary Contributor III

No problem. As I'm sure you know, to make the above into an Extension Attribute, put in something like the following:

#!/bin/sh

diskUsage=`df -h | awk '/disk0s*/{print $3}' | sed -e 's/[A-Z]/ &/' -e 's/i/B/'`

echo "<result>$diskUsage</result>"

I would consider making it an integer data so you can search on more than/less than values.

ooshnoo
Valued Contributor

Thanks again. At first it wasn't working, but then I realized I had to do a recon and it seems to do the trick!!!

brlittle
New Contributor

I had to come up with a way to check available drive space prior to allowing access to the Lion package installer in Self-Service. The EA reports the available space in GB as an integer, but you could easily munge the output to suit your needs.

#!/bin/sh

freeSpace=`df -h / | tail -1 | awk '{print $4}' | sed 's/.{2}$//' | bc -l`

echo "<result>$freeSpace</result>"

rcole
Contributor

@mm2270 and @brlittle Thanks for the Extension Attribute-based scripts. I am specifically looking to report the available Data partition, not the Boot partition, so I'm curious to see if either one of these does the trick after the next inventory update. Jamf needs to create this as a criteria, which seems to only be an issue now with the new APFS file structure. 

ccsshelpdesk
New Contributor III

We ideally need this also, need a smart group for size on the Data Volume.