Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Need Script to Delete Non-Admin Accounts upon Logout

I have a number of units in a lab that I need to automate the removal of the /Users folder of all the non-admin accounts when the user logs out. They all authenticate via AD (except local admin) and the user account data is not cached so if the network connection is lost, they can't log in either way. In the past I've simply gone around and manually removed all the user account folders within the /Users folder, except the admin and the Shared folder. As you can imagine this gets to be a pain. I'm thinking this is possible with a logouthook?, but I can't find how best to tackle it. All units in question are presently on 10.6.8, but soon we'll migrate to 10.7.


Now, the cats a$$ of this would be to have the option to specify a timestamp, so say the user logs back in within 24 hrs because they forgot to save something to their flash drive, they still have that option, but after the initial 24 hour period, then the user folder gets deleted. I'll gladly take the former as opposed to the fancy at this point.


I thank all the help I can get in advance.

MacBook Pro, Mac OS X (10.7.3), 15" Core i7

Posted on Feb 29, 2012 11:14 AM

Reply
3 replies

Mar 2, 2012 6:14 AM in response to Glenn Leblanc

I agree, the Guest account works like a charm and simply modifying the User Template to suit your environment is a breeze, but the Guest account isn't a solution in every instance.


I got it working for anyone that's interested…


I got this to work as a LogoutHook.


#!/bin/bash

# Logout script to remove nonadmin accounts from Users folder

# If user is an admin, exit script

if [ $USER = "usernametosave" ]; then

# the next 2 lines could be substituted for the previous line

# dscl . -read /Groups/admin GroupMembership | grep -q "$USER"

# if [ "$? -eq 0"]; then

echo "LOGOUT: admin folders will not be deleted."

exit1

fi


# If home directory exists, delete

if [ -d "/Users/$USER" ]; then

echo "LOGOUT: user account cleanup."

rm -R /Users/"$USER"

dscl . -delete /Users/"$USER"

fi

exit0


And then you make the script executable and write to the com.apple.loginwindow file. Then each time someone logs out it runs the script.

Need Script to Delete Non-Admin Accounts upon Logout

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.