Calculate Home Directory Sizes in Self Service

tkimpton
Valued Contributor II

Had a couple of occasions where laptop users are on SSD's and they run out of space

Thought i would share this

#!/bin/bash

# Get the currently logged in user
user=`ls -l /dev/console | cut -d " " -f4`

# Calculate the users home folder sizes
sizeU=`su - "${user}" -c 'du -shc ~/*'`

sudo /Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper 
-windowType utility -title "Your Home Directory Sizes" -description "$sizeU" -button1 "OK" 
-icon /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/HomeFolderIcon.icns -iconSize 96

I wanted to also add in some info about the boot volume using df -Hl /

Unfortunately it doesnt look user friendly.

Does any one have a suggestion?

2 ACCEPTED SOLUTIONS

CasperSally
Valued Contributor II

JAMF helped me come up with an ext attrib that reports back home dir size of logged in user. I know it's not exactly what you're looking for but it's helpful for us to create smart groups, etc. For our needs, we took the outlook cache file out of the size report, but that part could easily be removed

#!/bin/sh

# Locating the last logged in user.
lastUser=`defaults read /Library/Preferences/com.apple.loginwindow lastUserName`

# Calculating last Logged in user's Home Folder Size.
userHomeFolderSize=`du -sk /Users/$lastUser/ | awk '{ print $1 }'`

# Calculating last logged in user's Outlook Database Size
microsoftData=`du -sk /Users/$lastUser/Documents/Microsoft User Data | awk '{ print $1 }'`

# Subtracting out Outlook Database Size
totalSize=$(($userHomeFolderSize - $microsoftData))

# Converting from Kilobytes to Gigabytes
GIGABYTES=$(echo "scale=2;${totalSize}/1024/1024"|bc)

echo "<result>$GIGABYTES</result>"

View solution in original post

jomo
New Contributor III

by the way - the JSS always collects the Boot Drive filled in %. So you could also just have a Smart Computer Group for all Machines which have more that 70 % Boot Drive Full. Then have a Policy show them a Message that their HD is filling up and they should organise their files. Have this message show once a day until they get below 70% - if you have daily Inventory that is πŸ˜‰

View solution in original post

14 REPLIES 14

CasperSally
Valued Contributor II

JAMF helped me come up with an ext attrib that reports back home dir size of logged in user. I know it's not exactly what you're looking for but it's helpful for us to create smart groups, etc. For our needs, we took the outlook cache file out of the size report, but that part could easily be removed

#!/bin/sh

# Locating the last logged in user.
lastUser=`defaults read /Library/Preferences/com.apple.loginwindow lastUserName`

# Calculating last Logged in user's Home Folder Size.
userHomeFolderSize=`du -sk /Users/$lastUser/ | awk '{ print $1 }'`

# Calculating last logged in user's Outlook Database Size
microsoftData=`du -sk /Users/$lastUser/Documents/Microsoft User Data | awk '{ print $1 }'`

# Subtracting out Outlook Database Size
totalSize=$(($userHomeFolderSize - $microsoftData))

# Converting from Kilobytes to Gigabytes
GIGABYTES=$(echo "scale=2;${totalSize}/1024/1024"|bc)

echo "<result>$GIGABYTES</result>"

View solution in original post

jomo
New Contributor III

I guess i wouldn't like to have this running every time Inventory is performed. Also, for use via Self Service i would imagine it takes too long to still be a good experience for the user. Just tested it on my Computer (MBA with SSD) and it took ages to show any result.
Maybe have a launchdeamon running daily, preferable if the user is not active, creating a file somewhere with the values. Once the user clicks in it they would immediately see a value. That could also be collected through a EA.

jomo
New Contributor III

by the way - the JSS always collects the Boot Drive filled in %. So you could also just have a Smart Computer Group for all Machines which have more that 70 % Boot Drive Full. Then have a Policy show them a Message that their HD is filling up and they should organise their files. Have this message show once a day until they get below 70% - if you have daily Inventory that is πŸ˜‰

View solution in original post

tkimpton
Valued Contributor II

@jomo that's a brilliant idea. Thanks very much πŸ™‚

tkimpton
Valued Contributor II

@jomo i just implemented that and i can see a couple of machine in the smart group one being our master editing machine 😞

One thing i did notice is that there doesn't seem to be a Logs button (jss 9.21) to see if it ran or not if i just choose the user interaction message in the policy and may need to also install some kind of dummy file.

Just thought you guys should know if you wanted to do this as well.

jomo
New Contributor III

@tkimpton I just tested it on my JSS 9.21. I create a Policy with only the Message piece under "User Interaction" and once i was running at least once (!) at any machine then the "Logs" Button appears. As long as there are no Logs - the button doesn't show.

Also in the Policy under Scope you could limit the scope or even exclude specific machine/groups/buildings etc. if you don't want them to get this message.

mm2270
Legendary Contributor II

Just wanted to mention something regarding the use of Casper Suite's built in Boot Drive Filled % option. I'm personally not a big fan of using this because it can lead to some inaccurate assumptions, especially if you use it to trigger either end user notifications or alerts to yourself as an admin.
The issue is that 95% full of a 1 TB drive is a very different story from a 95% full 128 GB SSD. In the former, you're talking about having approx. 50 GB free space still. Not much to be alarmed about (other than the fact that someone has over 900 GBs of files of their Mac I guess πŸ˜› )
In the latter case, this would be reason to let the user know to clean up files since it means they probably only have 6 GBs of free space, so getting close to dangerous.

Because of the above, we use a free disk space Extension Attribute instead and store it as an integer, so we can trigger actions based on less than some value. I'm sure these types of EAs have been covered elsewhere. I recall @tlarkin][/url][/url][/url][/url or someone also posting one that used system_profiler to pull the value. Unfortunately for me it seems to pull a wrong value which I think may be related to the fact that we use FileVault 2 encryption.
Like anything there are multiple ways to skin this cat. Here is ours:

#!/bin/sh

DiskSpace=$(df -Hl | awk '//$/{print $4}' | sed 's/[A-Z]//')

echo "<result>$DiskSpace</result>"

It pulls the value in GBs, so we just named the EA something like "Free Disk Space (GBs)"

I know this is going a little off the original topic of pulling home directory sizes, but wanted to mention it since the use of the built-in % Boot Drive Full was mentioned.

tkimpton
Valued Contributor II

@mm270 thanks that's great I will give that a go in the morning πŸ™‚

jomo
New Contributor III

I agree and disagree πŸ˜‰

It doesn't really matter if your HD has 128 GB or 4 TB. Every HD suffers if its filled up - and that is always in relation to its full size. So - 95% filled is BAD. And it doesn't matter if the remaining space is 10 or 50 GB. Where i agree is that there is a difference between most SSD and SATA. Some SSD start causing issues already when they are more than 50% filled. The "normal" SATA should be good until 70%.

tkimpton
Valued Contributor II

@ jomo not sure what im doing wrong i have a a message scoped to just my machine and set for just self service to test it and i dont get any user message.

jomo
New Contributor III

hmmm....not sure what you are doing different. Thats what i just did for a test:

Create Smart Computer Group, Criteria = Boot Drive Percentage Full -> more than -> 70 %
Create a Policy
- Name it
- Enable it
- assign it to a category
- Trigger - Recurring Check-in
- Scope - the smart group just created
- User Interaction - Start Message -> type your Text

in 10.9 that message comes up like a Message Center Message - so it would only show shortly on the upper right of the screen. If you want it more "pressing" you would need to use a small script to leverage jamfHelper or any other displaymessage-method.

tkimpton
Valued Contributor II

ahhhh... on jss 9.21 user interaction doesnt work in self service 😞

there goes my testing.

https://jamfnation.jamfsoftware.com/discussion.html?id=8352

instead to test i open run jamf policy -id XXX and it works

I would put in a feature request but ... lol

rainingdogs
New Contributor

Hi, how to I make sure that inventory check is run before the above suggested on policy to notify users over usage of storage? TIA!

tdilossi
Contributor

Has anyone cleared excess files from the computers, and still had Jamf 10.2.2 report that the drive is too full? We are running into our SSD 256GB drives showing near maxed out, after the teacher clears their excess data, Jamf still shows 99-100% full, but the HD shows 40GB available.

Any ideas?