I've found plenty of excellent scripts for removing mobile accounts that create a home directory on login but I haven't found any that remove network account home directories.
I have some lab computers that do not "create mobile account at login" and a user home folder is created. These users are not in dscl so the scripts like the example below do not work for me. I'm trying to clear out the home folders for these network logins but don't know enough about bash to rework this script.
#!/bin/sh
userList=`dscl . list /Users UniqueID | awk '$2 > 1000 {print $1}'`
echo "Deleting account and home directory for the following users..."
for a in $userList ; do
find /Users -type d -maxdepth 1 -mindepth 1 -not -name "*.*" -mtime +7 | grep "$a";
if [[ $? == 0 ]]; then
dscl . delete /Users/"$a"; #delete the account
rm -r /Users/"$a"; #delete the home directory
fi
done
Inputting this line in terminal outputs the correct list of user's folders that I want deleted:
find /Users -type d -maxdepth 1 -mindepth 1 -not -name "*.*" -mtime +7
I'm just not sure how to change the variables to remove the dscl lines and have it rm -rf these listed user folders.