Posted on 10-05-2016 07:08 AM
Probably that is super-simple question, but please... How do I get the extension attribute value in the script?
There is EA with name, LDAP value $EXTENSIONATTRIBUTE_28, and it provides the correct info.
I need to use it in script. Should I send it to script as parameter? Should I call it in script anyhow?
Please help. Thanks!
Posted on 10-05-2016 07:40 AM
Can you explain further what you're looking to do here? Are you saying you want to use the same information that an EA script grabs in another script? Or did you mean something else?
EA scripts only get run at inventory collection, and the values they gather only get collected in order to send back to the JSS to update that computer's inventory record.
There are ways to send that gathered data from the EA into a local file each time its collected, or to take some action on the result, but I'm not sure if that's exactly what you're looking for here. If you can explain the situation a little more, I'm sure there is some solution that can be discussed.
Posted on 10-05-2016 08:25 AM
Yes, EA collects some information which I would like to use in script, and script is part of JSS policy.
Simple example - EA gets some user's info from LDAP, and I want to run simple notification policy shows me the pop-up window with EA value - or use that value for something in the script.
Thanks!
Posted on 10-05-2016 08:34 AM
I think what you're after is creating a variable, which is a stored piece of information that you can define in one part of a script and can be called up later in the script.
Without seeing the EA script, I assume you should be able to rip the line from the EA script that captures the information you're looking for, and drop it into a new script to use for the purpose you described. I don't see why that wouldn't be possible, but again, you haven't posted the EA script, so I'm only taking an educated guess.
The basic formats for capturing a variable is to either define it outright with syntax like
var="some string"
or capture the result of a command, more likely what you're talking about here, with something like:
var=$(commands that get the value go here)
Does that help?
Posted on 10-05-2016 09:01 AM
Yes. I am looking for how to make variable var getting the value of EA.
homeShare is the name of EA which gets info from LDAP. It works, shows in inventory screen correct value.
Posted on 10-05-2016 09:04 AM
I would like to use that value is policy, send it somehow to the script. Or just get value in the script - like we get $1, $2, $3, ect.
Posted on 10-05-2016 09:06 AM
If you want to pull down the value of an already stored extension attribute in a script running on a client you'll need to do an API call to get that value. It's certainly doable but I'm not sure why you wouldn't just copy the code that gets that value and grab it again.
Posted on 10-05-2016 09:11 AM
@iJake I can not just copy the code because EA value is collected from LDAP, not via script
Posted on 10-05-2016 09:12 AM
Then use the second syntax format I mentioned above. For example, say the line in the script that gets the string you want does something like this:
dscl "/Active Directory/DOMAIN/All Domains" read /Users/$loggedInUser SMBHome | awk '{print $NF}'
Then copy/paste that line (the relevant line from your EA script) into a new script, and turn it into a variable like:
var=$(dscl "/Active Directory/DOMAIN/All Domains" read /Users/$loggedInUser SMBHome | awk '{print $NF}')
Now you can use that variable by calling it later in the script. Simple example:
echo "$var"
Note that a variable is called in a script by placing a $
in front of the name of the variable you assigned.
I hope this is making sense. If you post the actual EA script, sanitized if necessary, and also the other script you want to use it in, I can help give you something more specific if needed. But the above should get you in the right direction.
Posted on 10-05-2016 09:17 AM
@mm2270 Thank you! Yes, I thought about getting Directory Attribute in script itself, just wondered if it is possible to send inventory info from JSS to the script which runs under JSS policy.
Why to collect info again if we already have it in JSS, right? :)
Posted on 10-05-2016 09:20 AM
@mm2270 's answer is definitely the way to go if your machines are bound but if they weren't and you needed to get this attribute it is definitely possible via the API. You'd want to have the credentials as script parameters in the policy for security assuming your JSS is locked down enough that they can exist there in clear text.
Posted on 10-05-2016 09:28 AM
Yes, as @iJake mentions, you could certainly pull the stored value from the Mac's JSS record using the API. It wasn't clear to me that's kind of what you may have been after. If so, then there are definitely threads that show how to grab an EA value using the API in a script.
One caveat to grabbing stored values with the API is that its only going to be as accurate as the Mac's last inventory collection. So that could mean its anywhere from minutes old to hours or even days out of date. That may not matter in this instance, but I thought I should mention that. Grabbing the value on the fly in a script (if applicable) will give you a more up to date result.
Posted on 10-05-2016 09:32 AM
Actually, that particular one is the bad example of that I am asking about.
Lets talk about some extra field in the JSS inventory, like "Internal Info". Might be just manual input or EA, it does not matter. Is there any way to send the value to the script which runs as part of JSS policy?
Posted on 10-05-2016 09:38 AM
If its manual entry then you'll need to use the API but if its an EA that is filled by a script then definitely in that case use that same code over again and generate that value in a script.
Posted on 10-05-2016 10:01 AM
Do I understand correct that there is no easy way just "send" EA value to script anyhow?
Posted on 10-05-2016 10:05 AM
@mhasman That is correct. If you want to use an EA value in the script, you have to pull it from the API.
Posted on 10-05-2016 10:09 AM
Thank you all for helping! You are the best!
Posted on 10-05-2016 10:48 AM
@mhasman I would modify my EA to save the data locally as wall as the JSS so I wouldn't have to use the API.
#!/bin/sh
#do magic EA stuff like LDAP lookups
echo "<result>$myEA</result>"
defaults write /Library/Preferences/com.bcbs.mhasman.plist EAResult -string $myEA.
then in the script you want that EA
#!/bin/sh
eaVal=$(defaults read /Library/Preferences/com.bcbs.mhasman.plist EAResult)
Posted on 10-05-2016 12:29 PM
@thoule Thank you sir!
Posted on 10-05-2016 02:43 PM
...