Ifconfig in extension attribute

valkyrie
New Contributor III

Hi! My network team needs some info, that I would ideally be able to get in an extension attribute.

I am running following script in a policy:

#!/bin/bash
ifconfig gpd0 | grep inet | awk '{print $2}'

Which gives me the needed info. However, being able to get it in an extension attribute would be easier to access for the network team.
Running the exact same script in an extension attribute, doesn't give me any info though. Does this have to do with the user the script is being run as?
Any thoughts on how to get the needed info in an extension attribute?

Thanks!

5 REPLIES 5

mschroder
Valued Contributor

The EA's don't take any output of a script, you need to format it properly

result=`ifconfig gpd0 | awk '/inet/{print $2}'
echo "<result>$result</result>

valkyrie
New Contributor III

Thanks! I wasn't sure how the EA needs to be formatted.

I tried the one you gave me, but sadly it isn't giving me any info either. I'm not familiar with scripting, as I've only started with it recently. Any ideas where it goes wrong?

edit: I did add the " at the end

valkyrie
New Contributor III

Ok, I now have

result=$(ifconfig gpd0 | awk '/inet/{print $2}')
echo "<result>$result</result>"

Which seems to be working.
However, I have 3 different responses:
- Some of them are blanc (which is expected, if the interface isn't active)
- One of the devices gives the wrong IP-address
- The rest of them give the same IP-address as each other, which is also a wrong IP-address voor the device

Tangentism
Contributor II

You could query what the active interface is then get its assigned IP.

#!/usr/bin/env bash

interface="$(route get default | grep interface | awk '{print $2}')"
result=$(ifconfig $interface | grep -v "inet6" | grep "inet" | awk '{print $2}')
echo "<result>$result</result>"

valkyrie
New Contributor III

The same problems seem to persist. Some IP's show up in Jamf, a lot of them are duplicates of each other, and some remain blank.
I am trying to extract the IP-address for gpd0 in an EA. It works fine in a policy, giving the correct IP-address each time the policy runs, so I'm a bit lost as to why it isn't working when it's being run as an EA.

The duplicate EA showing up also seems to be an issue with the EA template for the host name.