Skip to main content
Question

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

  • September 19, 2024
  • 4 replies
  • 37 views

Forum|alt.badge.img+1

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

Forum|alt.badge.img+8
  • Contributor
  • September 19, 2024

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


AJPinto
Forum|alt.badge.img+26
  • Legendary Contributor
  • September 19, 2024

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


Forum|alt.badge.img+8
  • Contributor
  • September 19, 2024

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


Shyamsundar
Forum|alt.badge.img+13
  • Jamf Heroes
  • October 8, 2024

try this

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