So I'm slowly learning that JAMF uses scripts to fill in a lot of gaps with automating processes (and rightfully so, if you know what you're doing it's definitely the way to go).
In my case, I don't totally know what I'm doing! Been scouring the forums today and found a bunch of scripts that can help me do what I'm trying to do, but I can't seem to piece this script together properly. I want to make a script that will run on a computer as a root, will check the users added locally to the computer. As long as they are not the account created by JAMF (the Management Account) or a Mobile account from AD, the script will remove the account and home folder from the computer the script is being ran on.
This is what I have:
#!/bin/sh
localUsers=$(dscl . list /Users UniqueID | grep -v "_" | awk '$2 < 1000 {print $1}')
For user in $localUsers
do
if [ "user" != "root" ] && [ "user" != "MGAdmin" ]
&& [ "user" != "daemon" ] && [ "user" != "nobody" ]
then
dscl . Delete /Users/$user
if [ $? = 0 ]; then echo "Removed user $user from computer";
fi
else
echo "User $user left alone"
fi
done
And now to explain my logic. I'm basically trying to check against UID first to make sure the UID is in the range of 500 - 999 (above 999 is a mobile account). I then do a check for "reserved" names that I don't want the script to touch, such as MGAdmin and root. If it passes those two conditions, the script will remove the account. Now I've checked the syntax in terminal, however the script fails at line 3 everytime. The script does not like how I'm using the awk command and it's taking "1000" as a file/directory. But meanwhile it doesn't do this when I manually type that whole line into terminal. And this is after simplifying that line of syntax as much as I could (eg, originally that line was doing an awk $2 > 500 && $2 < 999, but I could not get it to behave no matter how I lined up the parenthesis, quotes, etc. So I used the grep instead to help clean up the list before ignoring the mobile account altogether).
Any help you guys could provide would be greatly appreciated!