Extension Attribute Not Working - What am I doing wrong?

mcgace
New Contributor III

Hi,

I'm trying to report on which of out machines don't have Meraki Agent installed. I have created Extension Attribute and used a Smart Group but its not showing any machines as having Meraki Agent.

What am I doing wrong?

The script works in Terminal

#!/bin/bash PROFILE_ID="com.meraki.sm.mdm" if ( /usr/bin/profiles -P | /usr/bin/grep -q $PROFILE_ID ); then # Profile is present echo "<result>True</result>" exit 1 else # Profile isn't there, need to install echo "<result>False</result>" exit 0 fi

497c906f03f3455f9fd353891fd15cbd

1 ACCEPTED SOLUTION

mschroder
Valued Contributor

Hm, that is an interesting case. Seems when I pipe something to grep the exit code is not what 'man grep' promises - I always get '0'.

But why do do you need a EA for this? The MDM already knows which Profiles are installed. So just base your smart group on the criteria 'Profile Identifier' 'is' 'com.meraki.sm.mdm'.

View solution in original post

4 REPLIES 4

mschroder
Valued Contributor

Hm, that is an interesting case. Seems when I pipe something to grep the exit code is not what 'man grep' promises - I always get '0'.

But why do do you need a EA for this? The MDM already knows which Profiles are installed. So just base your smart group on the criteria 'Profile Identifier' 'is' 'com.meraki.sm.mdm'.

View solution in original post

tthurman
Contributor III

@mcgace

You could try something like this....
Instead of using the if command to do the true/false on the error code return value. Assign the return of the command to a variable and use the if to validate against that.

In this case, I'm just using a count on the return from grep.

#!/bin/bash

PROFILE_ID="com.meraki.sm.mdm"
profileCheck=$(sudo /usr/bin/profiles -P | /usr/bin/grep -c -i $PROFILE_ID)


if [[ $profileCheck == "1" ]] 
then
    # Profile is present
    echo "<result>True</result>"
    exit 1
elif [[ $profileCheck == "0" ]]
then
    # Profile isn't there, need to install
    echo "<result>False</result>"
    exit 0
elif [[ $profileCheck -gt "1" ]]
then
    #Profile count greater than 1 - potential issue.
    echo "<result>Remediate</result>"
else
    #Something went wrong.
    echo "<result>Unknown - Error</result>"
fi

Mauricio
Contributor II

@mcgace Have you tried to comment out the exit lines, especially the exit 1?

As you said it works in Terminal but JSS may get that exit 1 as a failure and not send the info upstream (not sure as I always end my EAs scripts with exit 0).

#!/bin/bash

PROFILE_ID="com.meraki.sm.mdm"

if ( /usr/bin/profiles -P | /usr/bin/grep -q $PROFILE_ID ); then
    # Profile is present
    echo "<result>True</result>"
    #exit 1
else
    # Profile isn't there, need to install
    echo "<result>False</result>"
    #exit 0
fi

exit 0

Regards

mcgace
New Contributor III

Thanks guys, all valid responses and they do work as solutions. @mschroder was right, I am making extra work for no reason, so I based Smart Group on Profile Identifier