Skip to content

Instantly share code, notes, and snippets.

@rickychilcott
Last active May 5, 2017 00:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rickychilcott/6104913 to your computer and use it in GitHub Desktop.
Save rickychilcott/6104913 to your computer and use it in GitHub Desktop.
Remove outdated users
#!/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