07-16-2021 10:01 AM - edited 07-16-2021 10:30 AM
Hey everyone. Looking to create a smart group, via an Extension attribute, that looks for every MacOS device that has the home folder 'test'. So /Users/test. Having trouble putting together the script for the extension attribute that can look or every device with this home folder. Would appreciate some help.
I then want to delete that home folder for all confirmed devices by scoping the smart group and using the command 'sudo rm -rf /Users/test'. Does this seem like a reasonable way to accomplish this?
I guess I could just blast every device with this command, but that seems a little unwise... 😉
EDIT- I got the script figured out (see below), but still looking for advice on best approach for deleting the home folder on devices that have it. Thanks.
#!/bin/bash
if [ -d /users/ ]; then
echo "<result>Has test Folder</result>"
else
echo "<result>Does Not Have test Folder</result>"
fi
exit
Solved! Go to Solution.
Posted on 07-16-2021 10:28 AM
This should probably accomplish what you need for detection.
#!/bin/sh
path="/Users/test"
result="false"
if [ -d "$path" ]; then
result="true"
fi
echo "<result>$result</result>"
Posted on 07-16-2021 10:28 AM
This should probably accomplish what you need for detection.
#!/bin/sh
path="/Users/test"
result="false"
if [ -d "$path" ]; then
result="true"
fi
echo "<result>$result</result>"
Posted on 07-16-2021 10:41 AM
Thanks. Works great. Thought I had it with the script I just posted, but my version seems to be giving inaccurate results.
07-16-2021 12:28 PM - edited 07-16-2021 12:29 PM
@andrew_betts The script you posted is just checking for the root directory /users (which should be /Users as in @andrew_nicholas's example) not a folder for a user named "test" inside it. If that folder belongs to an actual user you _really_ do not want to just delete the folder. I forget what version of macOS added the command, but the preferred way to delete a user since at least macOS 10.12 is the sysadminctl command, and to delete the user test, and their folder in /Users, you'd run this command:
/usr/sbin/sysadminctl -deleteUser test
07-16-2021 12:53 PM - edited 07-16-2021 01:15 PM
Thanks. No, the folder doesn't belong to any local user. The situation is that sometime ago, I composed a pkg via Composer and didn't exclude Users or Library when packaging- so all devices that installed the app got some random home folder (named after the test user I was composing with). I don't think there is any harm in the folder being there and the contents seem to be of no consequence, but still- thought it would be best to delete. I could have worked backwards and just deleted the home folder by scoping the devices that took the pkg, but it has gone through a few iterations, only one of which gave devices the extra home folder. Hope that makes sense.