Menu Close

Disk Usage Report Self Service Policy

To aid end-users in determining where all their hard drive space has gone, we have a Self Service policy which leverages du and outputs text files of the top 75 directories of the root volume and the user’s home folder. The utilitarian results are sorted by size, in gigabytes, and saved to the user’s desktop.

Self Service Description

Disk Usage Report Outputs two text files to your Desktop, which includes a listing of the top 75 directories of the root volume and the top 75 directories of your user folder. The results are saved to your desktop as: Computer-DiskUsage.txt and {YourUserName}-DiskUsage.txt.

Disk Usage: Root Volume

#!/bin/sh
####################################################################################################
#
# ABOUT
#
#   Disk Usage
#
####################################################################################################
#
# HISTORY
#
#   Version 1.0, 8-Dec-2014, Dan K. Snelson
#
####################################################################################################
# Import logging functions
source /path/to/logging/script/logging.sh
####################################################################################################

loggedInUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`
loggedInUserHome=`dscl . -read /Users/$loggedInUser | grep NFSHomeDirectory: | cut -c 19- | head -n 1`
machineName=`scutil --get LocalHostName`

/bin/echo "`now` *** Calculate Disk Usage for / ***" >> $logFile

/usr/bin/du -axrg / | sort -nr | head -n 75 > $loggedInUserHome/Desktop/$machineName-ComputerDiskUsage.txt


exit 0      ## Success
exit 1      ## Failure

Disk Usage: Home Directory

#!/bin/sh
####################################################################################################
#
# ABOUT
#
#   Disk Usage
#
####################################################################################################
#
# HISTORY
#
#   Version 1.0, 8-Dec-2014, Dan K. Snelson
#
####################################################################################################
# Import logging functions
source /path/to/logging/script/logging.sh
####################################################################################################

loggedInUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`
loggedInUserHome=`dscl . -read /Users/$loggedInUser | grep NFSHomeDirectory: | cut -c 19- | head -n 1`

/bin/echo "`now` *** Calculate Disk Usage for $loggedInUserHome  ***" >> $logFile

/usr/bin/du -axrg "$loggedInUserHome" | sort -nr | head -n 75 > "$loggedInUserHome"/Desktop/"$loggedInUser"-DiskUsage.txt


exit 0      ## Success
exit 1      ## Failure
Posted in Jamf Pro, Scripts, Tips & Tricks

Related Posts