Skip to content

zaren/DeleteUsers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 

Repository files navigation

DeleteUsers

DeleteUsers

DeleteUsers is available as both a script and an application that will delete user account data off of a macOS machine, excluding any pre-defined users.

Why?

Managed lab machines have a tendency to run low on space, as users will occasionally leave large amounts of content behind. I put this application together to help streamline the deletion process. Having seen several requests for how to do something like this in the MacAdmins Slack, I decided to make my version of this tool public as sample code. Feel free to tinker with it and modify it to fit your needs.

This application can be manually run at any time to delete user accounts, while the script can be used to automate the process.

Disclaimer

The following code is provide as a community resource and as sample code for testing purposes, and is licensed under the terms of Apache license 2.0. No warranty is expressed or implied. Any results from the execution of the following code are 100% the responsiblity of the downloader and executor.

Installation

The application can be stored anywhere on the machine, but it is recommended that it be kept in a location only accessible by those with admin access.

The script is intended to run automatically by way of the periodic utility - placing it in /etc/periodic/daily would be good for a higher traffic lab. (See https://www.alansiu.net/2020/08/26/running-daily-weekly-and-monthly-scripts-in-macos-using-periodic/ for more info.)

VERY IMPORTANT! Make sure you edit these scripts BEFORE first run!

This script will delete ALL user accounts on the machine, with the exceptions of the currently logged in user, and those accounts delcared within the script. By default, the line in the script that declares those accounts is

for home in $(ls /Users | grep -v -e admin -e Shared -e root -e loginwindow)

You may add your admin / testing / other accounts of value to this line by adding additional -e account_name entries to that line.

Changes can be made within the executable by editing /DeleteUsers.app/Contents/Resources/script

Usage

When you launch the application, you will be prompted for admin rights:

admin rights

From there, the main app window will appear (the "Details" window is closed on first launch, but can be toggled open to see a list of deleted users):

main window

Once the application finds a user to delete, it will prompt you again for permission to admin your computer:

admin

After all users have been deleted, the script will finish, prompting you to quit the application:

done

The periodic script will delete user accounts once a drive space usage percentage is reached, with no interaction needed. That amount is defined under the limit variable.

If the script executes and deletes users, it will send an email through sendmail on the local macihne. Subject, recipients, and content are defined in the following line:

echo "To: admin@example.com\ncc: other_admin@example.com\nSubject: Disk usage $usep% on $(hostname)\nLocal storage has exceeded $limit%. The following users were automatically deleted: $deletedUsers" | sendmail -f admin@example.com -t admin@example.com other_admin@example.com

Fiddly bits

This is a very blunt object of a script. Once you give it your admin password, accounts WILL be deleted with no further prompting, and will continue to be deleted until /Users has been scanned completely. Please be sure there is no data that is needed to be saved from those accounts, because it won't be there once you set the script loose.

About

Script and executable to facilitate the deletion of macOS user accounts

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages