Boot Volume Free Space EA

Look
Valued Contributor III

The current Boot Volume Free Space EA on Jamfnation doesn't deal well with > 1 TB drives (the field it references uses a varying unit).
How are these updated?
I am using a variation on the script it contains.

free=$(diskutil info / | awk '/Free Space/ { print $6 }' | sed s/(//)
freeGB=$(expr $free / 1000000000)
echo "<result>"${freeGB%.*}"</result>"

This may not be the best way but it seems to work. Just felt it needed mentioning in case anyone was wondering why they keep getting 1 GB returned...

6 REPLIES 6

chris_kemp
Contributor III

I just added a line to pull the unit of measure from diskutil, which then returns 1 TB (or more, for larger volumes):

#!/bin/sh
free=`diskutil info /Volumes/Video Store/ | grep "Free Space"| awk '{print $4}'`

unit=`diskutil info /Volumes/Video Store/ | grep "Free Space"| awk '{print $5}'`

echo "<result>"${free%.*} $unit"</result>"

It's still rounded off to 1 TB, 2 TB, etc. but then as long as they have THAT much space I really don't care to be exact. ;-)

Look
Valued Contributor III

The problem with that approach is it is no longer an integer and I like to use greater than functions against it in smart groups.

iJake
Valued Contributor

You should use DF

usedBlocks=`df / | sed -n 2p | tr -s ' ' | cut -d " " -f3`
availableBlocks=`df / | sed -n 2p | tr -s ' ' | cut -d " " -f4`
totalBlocks=$(echo "$usedBlocks+$availableBlocks" | bc -l )
usedDisk=$(echo "($availableBlocks/$totalBlocks)*100" | bc -l | cut -c1-5)

tinsun
New Contributor II

We're currently using the following python script as an EA. It will show the disk mounted on /'s free space in GB. Real GB should of course use 1024 instead of 1000 as below, but since the finder apparently use 1000 as the base for its free space calculation, I'm using it in the script below as well:

#!/usr/bin/python
import os
st = os.statvfs("/")
print "<result>%0.2f</result>" % (st.f_bavail * st.f_frsize / 1000 / 1000 / 1000)

bpavlov
Honored Contributor

I think the fact that this is even needed is silly. This is hardware information that should be collected by Casper.

I put in a feature request for it but was blown off: https://jamfnation.jamfsoftware.com/featureRequest.html?id=2837

Maybe others here can post there and convince the powers that be otherwise.

Look
Valued Contributor III

Just resurrecting an ancient thread to address a couple of points.
1: We have moved to the much simpler

df -g / | awk '/dev/ {print $4}'

To get the value for free space in GB.

2: Now that JAMF have implemented a builtin MB free attribute is anyone else finding it is showing twice the actual free space? We also have this issue with the display of free space under storage for a device as well. Curious as to whether this is just us or everyone is showing it incorrectly like this. You can even do simple maths on the volume size and percent used to see it is obviously along way away from correct.