Last active
May 5, 2017 00:15
-
-
Save rickychilcott/6104913 to your computer and use it in GitHub Desktop.
Remove outdated users
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/administrator | |
/Users/sccadmin | |
/Users/scclab | |
/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 | |
echo "Inspecting $user. Should it be kept??" | |
# Keep select accounts | |
for kept_user in $KEEP ; do | |
if [[ "$user" == "$kept_user" ]]; then | |
echo "Yes, keep $user" | |
user="" | |
break # no need to continue if we've found a match | |
fi | |
done | |
if [[ "$user" != "" ]]; then | |
echo "No, goodbye $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