Novice scripter trying to modify a script from github to delete all empty usergroups from Jamf.
Currently getting line 26: syntax error near u'expected token `do
Eventually I want this script to also delete empty classes as well.
#!/bin/bash
# Script to delete empty usergroups
#
jssUser="******" # Full JSS Admin Account
jssPass="******" # Password for the JSS Admin Account
index="0"
usergroups=()
echo $jssURL
IDs=`curl -sk -u $jssUser:$jssPass -H "Accept: text/xml" "https://******.jamfcloud.com/JSSResource/usergroups" -X GET`
#
#
size=`echo $IDs | xpath //user_groups/size | sed 's/<[^>]*>//g'`
#
#
echo $size " user groups will be scanned."
#
#Put the IDs into an array
while [ $index -lt ${size} ]
do
index=$[$index+1]
usergroups+=(`echo $IDs | xpath //user_groups/user_group[${index}]/id | sed 's/<[^>]*>//g'`)
done
#
# Sort through each user ID individually and grep for IDs size
for i in "${usergroups[@]}"
do
usergroup=`curl -sk -u $jssUser:$jssPass -H "Accept: text/xml" "https://******.jamfcloud.com/JSSResource/usergroups/id/${i}" -X GET`
groupsize=`echo $usergroup | xpath //user_group/users/size | grep id`
#
# Delete users that meet our criteria
if [[$groupsize -eq 0]] ; then
echo "Deleting ${i}"
curl -k -v -u $jssUser:$jssPass -H "Accept: text/xml" "https://******.jamfcloud.com/JSSResource/usergroups/id/${i}" -X DELETE
fi
done