Skip to content

Lynna Jackson

Lab/Classroom Computer and Software Managment

  • Home
  • The 100 mile view

Mac OS – Remove Inactive Users

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
This entry was posted in Labs and tagged Macintosh, User_Profile on October 19, 2017 by Lynna Jackson.

Post navigation

← Stata – Creating an Installer Windows 10 – Check for service status and restart if not running →

Tags

  • Active_Directory
  • Adobe
  • AFP
  • ARD
  • Background
  • Boot
  • Bootcamp
  • Chrome
  • Command
  • Default User
  • DEP
  • Deployment
  • Dual_Boot
  • El Capitan
  • External boot
  • GIS
  • Group_Policy
  • High Sierra
  • Image
  • Installer
  • JAMF
  • KACE
  • Keyserver
  • Kiosk
  • Lion
  • Login
  • Macintosh
  • Matlab
  • Mavericks
  • Mt Lion
  • Novell
  • Packaging
  • Reference
  • Security
  • Silent Installer
  • SIP
  • Sleep
  • Software
  • Spss
  • Startup
  • User_Profile
  • VectorWorks
  • Windows
  • Windows 10
  • Windows to Go

Contact Me

Contact me by email ... [email protected]
Proudly powered by WordPress