Created
August 7, 2012 12:50
-
-
Save rickychilcott/3285060 to your computer and use it in GitHub Desktop.
Remove Unused Accounts (with keepable list)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# List of users to keep | |
KEEP=$( cat <<EOL | |
/Users/admin | |
/Users/sccadmin | |
/Users/mdiaadmin | |
/Users/Shared | |
/Users/Search | |
EOL); | |
# Number of days to keep | |
DAYS=30 | |
USERLIST=`find /Users -type d -maxdepth 1 -mindepth 1 -not -name "*.*" -mtime +$DAYS` | |
for user in $USERLIST ; do | |
# Keep select accounts | |
for keep in $KEEP ; do | |
[[ "$user" == "$keep" ]] && user="" && continue | |
done | |
# Remove user's home directory and DSCL entry | |
if [[ "$user" != "" ]]; then | |
echo "Deleting account and home directory for" $user | |
dscl . delete $user #delete the account | |
rm -r $user #delete the home directory | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment