Skip to main content
Question

Need a script that will find old users and then delete them


Forum|alt.badge.img+1

I need a script that will find old users and then delete them.

So far I have this script:

#!/bin/bash

# Loop through users with homes in /Users; exclude any accounts you don't want removed (i.e. local admin and current user if policy runs while someone is logged in)

for username in `ls /Users | grep -v localadmin | grep -v Shared`
do
if [[ $username == `ls -l /dev/console | awk '{print $3}'` ]]; then
echo "Skipping user: $username (current user)"
else
echo "Removing user: $username"

# Optional, removes the account
sudo dscl . delete /Users/$username

# Removes the user directory
sudo rm -rf /Users/$username
fi
done

0 replies

Be the first to reply!

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings