Averaging home folder sizes

tanderson
Contributor

I have a couple of projects I'm working on where it would be helpful to know the average size of our users' home folders. I see that information in the JSS on a per user basis when viewing the Accounts section of Computer Details. Any ideas on how it's stored in the JSS or how to get that same info into something I can export out and work up in Excel?

We have some people here that are comfortable with writing SQL queries if that's an option. Thanks.

11 REPLIES 11

stevewood
Honored Contributor II
Honored Contributor II

A fairly simple way to do it without having to dig into the database via SQL, would be to use an Extension Attribute to gather the home folder size, then use an Advanced Search to get the info out of the JSS in an CSV file.

EA:

##################
#!/bin/sh

if [ -e /Users/$3 ];
then

mysize=`du -hs /Users/$3`
echo "<result>$mysize</result>"

else

mysize=`du -hs /Volumes/Users/$3`
echo "<result>$mysize</result>"

fi
###################

Then just go into Inventory and choose an Advanced Search. Deselect everything but computer name and the Home Folder size EA. Run the search whenever you need to, and then export as a CSV.

HTH

Steve

tanderson
Contributor

I'll give this a run. Thanks Steve!

quedayone
Contributor

I like this one!

znilsson
Contributor II

When I set this as an extension attribute and run a search, the home folder size EA column is empty. If I just run it as a script via casper remote, it works. However it does seem to need time to calculate the home folder size, in my case it takes about 20 seconds before I get a result from the script, I have close to 100GB in my home directory.

So is the time it needs to calculate the size the reason it's not showing up in the advanced search via the EA?

mm2270
Legendary Contributor III

$3 shouldn't be used in Extension Attribute scripts. That only gets the logged in user info when run from a Self Service policy, login or logout triggers, etc. When the same script is run during a normal inventory collection, it will not know what $3 refers to so it will come back blank.

Replace $3 with $loggedInUser, and set loggedInUser up front in the script with:

loggedInUser=$(ls -l /dev/console | awk '{print $3}')

znilsson
Contributor II

Thanks. I tried that, but still not showing up via the EA, and it didn't work as a standalone script either - pretty sure I have some context wrong.

#!/bin/sh

loggedInUser=$(ls -l /dev/console | awk '{print $3}')

if [ -e /Users/loggedInUser ];
then

mysize=`du -hs /Users/loggedInUser`
echo "<result>$mysize</result>"

else

mysize=`du -hs /Volumes/Users/loggedInUser`
echo "<result>$mysize</result>"

fi

stevewood
Honored Contributor II
Honored Contributor II

@znilsson two things: 1) you need a $ in front of your loggedInUser in the if statements:

#!/bin/sh

loggedInUser=$(ls -l /dev/console | awk '{print $3}')

if [ -e /Users/$loggedInUser ];
then

mysize=`du -hs /Users/$loggedInUser`
echo "<result>$mysize</result>"

else

mysize=`du -hs /Volumes/Users/$loggedInUser`
echo "<result>$mysize</result>"

fi

Second, I would recommend re-thinking putting that as an EA. That script will run EVERY time a recon is done. If you have users that have large home folders, they will feel it. I used to do it as an EA and wound up taking it out because it lengthened the recon process and my users felt it.

stevewood
Honored Contributor II
Honored Contributor II

Ha, and I realize I was the one that posted that script to begin with, and like @mm2270 said, $3 won't populate unless run at login/logout/self service.

znilsson
Contributor II

I knew it was something stupid on my part. Yeah I need to get this information for a report I'm running, I'm planning on disabling this EA once my report is run.

I put the $ in place, and it worked on one machine out of 96. Is this something that will populate once these machines check in with Casper?

stevewood
Honored Contributor II
Honored Contributor II

@znilsson yes, the next time a machine updates its inventory in the JSS, your EA will be populated. Remember, a check in is different than an inventory update. If you want to trigger an inventory update immediately, or at next check in, create a new policy that is set to trigger at check in, once per computer, and has the Update Inventory check box checked under Maintenance. You can delete this policy once your EA is populated.

znilsson
Contributor II

Thanks for your help guys. It's currently populating as inventory updates come in.