Darshan Hiranandani : can I use grep to find a profile with a name that consists of multiple words?

darshanhira
New Contributor II

I’m currently developing a remediation policy for Self Service that triggers the uninstall and reinstall of a profile. While I can successfully remove and reinstall the profile, I need a verification step to check if the profile was reinstalled. I'm using the following command:

bash

profiles show -o stdout | grep "ProfileDisplayName = "$profileName"" | /usr/bin/awk '{print $3}' | sed 's/[[:punct:]]//g'
This works perfectly for single-word profile names, like "Zoom," but fails with multi-word names, such as "Zoom Profile," resulting in "no such file or directory." I’ve tried enclosing the profile name in both single and double quotes, and using "${profileName}", but nothing seems to work.

Could anyone suggest how to modify the command so it successfully handles profile names with more than one word? Here’s the function I created for verification:

bash

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
}
Thanks for your help!
Regards

Darshan Hiranandani

4 REPLIES 4

shannon_pasto
Contributor

You’re probably be better off grepping for the UUID of the profile instead.

AJPinto
Honored Contributor III

Almost this exact question was asked last week, strange. However, there is a solution in that post you should probably look at.

 

Solved: How to grep a profile named with more than one wor... - Jamf Nation Community - 324834

shannon_pasto
Contributor

I tend to prefer the unique identifier as the profile name can change, it also avoids issues with non-alpha characters

Shyamsundar
Contributor

try this

profiles show -o stdout | grep "ProfileDisplayName" | grep "$profileName"