Harddrive space - EA

Captainamerica
Contributor II

I am trying to find a working extension attribute for space. Most interested in space left on drive in Megabytes - or maybe also the total capacity

Have found the following that I put into a EA - but don´t seem to work as nothing is rapported

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE extensionAttribute PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<extensionAttribute>
  <displayName>Boot Volume Free Space</displayName>
  <displayInCategory/>
  <dataType>integer</dataType>
  <description>Returns the free space on the current boot volume in GB, rounded down to the nearest integer.</description>
  <scriptContentsMac>#!/bin/bash

free=`diskutil info /|grep "Free Space"|awk '{print $4}'`

echo "&lt;result&gt;"${free%.*}"&lt;/result&gt;"</scriptContentsMac>
</extensionAttribute>

Do any has some working on this on Mojave?

7 REPLIES 7

ericbenfer
Contributor III

There is already a native Jamf inventory for “Boot Drive Available MB” and “Boot Drive Pecentage Full”. Would those work for you?

Captainamerica
Contributor II

Arh yes . I actually looked on the extension but looked at harddrive/volume where there was nothing

mm2270
Legendary Contributor III

Try this for the EA:

#!/bin/bash

echo "<result>$(diskutil info / | awk '/Free Space|Available Space/{print $4}')</result>"

The reason you're not getting any results is because, I think around 10.12, it changed from "Volume Free Space to "Volume Available Space"
The EA above should work on older OSes and current ones as it looks for either term.

I suggest saving it as an integer style EA, then you can use it to create Smart Groups using a greater than or less than modifier.

user-HKroWEoJlf
New Contributor

I was able to get the following script to work for me but, I haven't been able to modify the script to make the unit(GB) show up after the free space amount is listed. Any help/ideal would be greatly appreciated!

!/bin/bash

echo "<result>$(diskutil info / | awk '/Free Space|Available Space/{print $4}')</result>"

efil4xiN
Contributor II

add the 5th column, it would be diskutil info / | awk '/Free Space|Available Space/{print $4,$5}'

Going to give this a try and report back. Running Catalina and Big Sur. Curious about this... Specifically:

#!/bin/bash

echo "<result>$(diskutil info / | awk '/Free Space|Available Space/{print $4,$5}')</result>"

@efil4xiN and @user-HKroWEoJlf 

Hey @rcole 

 

 I ended up going with

#!/bin/sh
#https://www.jamf.com/jamf-nation/discussions/12546/boot-volume-free-space-ea


DU=$(df -h / | awk 'END{ print $(NF-4) }')


echo "<result>$DU</result>"

the following which works in Catalina and Big Sur. As always ..test,test,test