Skip to main content
Question

Boot Volume Free Space EA

  • November 11, 2014
  • 6 replies
  • 51 views

Forum|alt.badge.img+16
  • Valued Contributor

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

chris_kemp
Forum|alt.badge.img+20
  • Jamf Heroes
  • November 12, 2014

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. ;-)


Forum|alt.badge.img+16
  • Author
  • Valued Contributor
  • November 12, 2014

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
Forum|alt.badge.img+23
  • Contributor
  • November 12, 2014

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)

Forum|alt.badge.img+7
  • Contributor
  • November 14, 2014

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
Forum|alt.badge.img+18
  • Esteemed Contributor
  • February 7, 2015

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.


Forum|alt.badge.img+16
  • Author
  • Valued Contributor
  • July 20, 2017

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.