Sonoma Regex works in Smart Group, not in Extension Attributes

afnpw
New Contributor III

Hello everyone, 

 

We use an extension attribute that will identify the Max supported macOS by going through OS regexs. For Sonoma, we are using the regex below 

SonomaRegEx="(^Mac1[3-9]|MacBook\d{2}|MacBookAir([8-9]|\d{2})|Macmini([8-9]|\d{2})|MacPro([7-9]|1\d)|iMacPro[1-9]|iMac(1[8-9]|2[0-9]),\d|MacBookPro(1[4-9]|2[0-9]),\d)"

 

And it will identify it's maxOS with: 

# Compare Model Identifier against Sonoma Regex compatible Macs
if [[ $myModel =~ $SonomaRegEx ]]; then
maxOS="14"
fi

 

So far, it's working partially. As devices are updating inventory I am seeing them update, but on my Macbook Air (m1, 2020) it will not show up as Max OS 14. It does, however show up in a smart group where it searches for Model Identifier matching the regex. 

 

Is there anything obvious that I am missing? 

 

1 ACCEPTED SOLUTION

TrentO
Contributor II

More than likely the issue is that the flavor of regex used in your shell's conditionals is incompatible with the flavor you are using in the smart group. For example, if your script is written in zsh, by default it does not support shortcuts such as \d for digits. Instead you have to use the full POSIX bracket notation [[:digit:]]. In your script, \d was interpreted as a literal "d" which meant that \d{2} was not 2 digits but instead literally "dd". So, MacBookAir([8-9]|\d{2}) does not match "MacBookAir10,1" but MacBookAir([8-9]|[[:digit:]]{2}) will.

 

So in your EA script you could use this instead:

 

SonomaRegEx="^(Mac1[3-9]|MacBook[[:digit:]]{2}|MacBookAir([8-9]|[[:digit:]]{2})|Macmini([8-9]|[[:digit:]]{2})|MacPro([7-9]|1[[:digit:]])|iMacPro[1-9]|iMac(1[8-9]|2[0-9]),[[:digit:]]|MacBookPro(1[4-9]|2[0-9]),[[:digit:]])"

 

 

**Also please note that I moved your ^ outside your parentheses so it get's applied to all of the model types. As it was written, only the Mac1[3-9] option was required to be at the beginning of the matched string. 

 

View solution in original post

4 REPLIES 4

pete_c
Contributor III

You can't read one EA from a separate EA. You might want to try putting both calculations into a single EA instead, then using that for your Smart Group criteria.

 

I've been using this without any problems:
 https://github.com/MLBZ521/MacAdmin/blob/master/Jamf%20Pro/Extension%20Attributes/Get-LatestOSSuppor...

afnpw
New Contributor III

My bad, it is part of the same EA. Just copy/pasted the relevant bits separately. 

TrentO
Contributor II

More than likely the issue is that the flavor of regex used in your shell's conditionals is incompatible with the flavor you are using in the smart group. For example, if your script is written in zsh, by default it does not support shortcuts such as \d for digits. Instead you have to use the full POSIX bracket notation [[:digit:]]. In your script, \d was interpreted as a literal "d" which meant that \d{2} was not 2 digits but instead literally "dd". So, MacBookAir([8-9]|\d{2}) does not match "MacBookAir10,1" but MacBookAir([8-9]|[[:digit:]]{2}) will.

 

So in your EA script you could use this instead:

 

SonomaRegEx="^(Mac1[3-9]|MacBook[[:digit:]]{2}|MacBookAir([8-9]|[[:digit:]]{2})|Macmini([8-9]|[[:digit:]]{2})|MacPro([7-9]|1[[:digit:]])|iMacPro[1-9]|iMac(1[8-9]|2[0-9]),[[:digit:]]|MacBookPro(1[4-9]|2[0-9]),[[:digit:]])"

 

 

**Also please note that I moved your ^ outside your parentheses so it get's applied to all of the model types. As it was written, only the Mac1[3-9] option was required to be at the beginning of the matched string. 

 

afnpw
New Contributor III

Hey, thank you very much. At least on the computer that wasn't working I am seeing it fixed. Also appreciate learning what the issue was. 

 

Thanks again,