I am working on a remediation policy for Self Service that will trigger the uninstall and then reinstall of a profile. Doing this is easy to do. I created a smart group then excluded the smart group from the profile I was testing with. Once the policy causes the Mac to be added to the smart group, the profile gets removed. When the Mac is removed from the smart group the profile is installed again. But there's a problem... I wanted to have a step that would verify the the profile did get reinstalled. To do that, I used this command:
profiles show -o stdout | grep "ProfileDisplayName = "ProfileName"" | /usr/bin/awk '{print $3}' | sed 's/[[:punct:]]//g')
When I was testing this on my own Mac and a test Mac, I was testing removing a profile we have for Zoom. The profile is simply named "Zoom". The command above works perfectly for a profile named with just one word. If the profile is named something like "Zoom Profile" the command will output "no such file or directory". I have tried putting the profile name in double quotes and single quotes. Since I'm using a variable called profileName in the command I have also tried using "${profileName}". The command simply won't work with a profile name with more than one word. Can anyone tell me how to get this to work? The script that handles the uninstall and reinstall of the profile works perfectly. It's just this verification step that doesn't work. Here's the function I created for verification:
# Check if profile was reinstalled
function checkInstall() {
installed=$(profiles show -o stdout | grep "ProfileDisplayName = "$profileName"" | /usr/bin/awk '{print $3}' | sed 's/[[:punct:]]//g')
if [ "$installed" = "$profileName" ]; then
log "Profile "$profileName" was installed successfully"
elif [ "$installed" != "$profileName" ]; then
log "Profile "$profileName" install failed"
fi
}