Each user that logs into one of the macs I support takes up almost 500 MB of space for their "home" directory. With some of my macs having hundreds of users these home directories can fill up the disk. Also, on my macs, AD users don't create an account on the machine but they do create a home directory. Therefore, I don't have an account to remove, just the home directory.
I created this script to search for and remove the user's home directory for users that have not logged in in over 14 days. Using our JAMF server I can target macs with a disk that is 80% or more full to run this script.
#!/bin/sh
# Lynna Jackson, Williams College, Oct 19 2017
#finds users who haven't logged in in over 21 days and if they
#aren't a "protected" account, deletes the user's directory
usersToDelete=`find /Users -type d -maxdepth 1 -mindepth 1 -mtime +14`
for a in $usersToDelete ; do
case "$a" in "/Users/labadmin"|"/Users/Shared"|"/Users/root")
# Don't delete these accounts
echo ""$a" Protected User Not being deleted"
;;
*)
echo "Deleting: "$a""
rm -R "$a"
;;
esac
done