Skip to main content
Solved

Script to Capture Extension Attribute Value Returns Nothing


Forum|alt.badge.img+7

Hi everyone,

I have mashed together the following script to report a managed device's current LAPS password, which is stored as an extension attribute on the JSS.

Unfortunately, when I run the script, nothing is returned (no errors either).

#!/bin/bash

apiUser=""
apiPass=""
apiURL=$(/usr/bin/defaults read /Library/Preferences/com.jamfsoftware.jamf.plist jss_url | sed 's|/$||')
udid=$(/usr/sbin/system_profiler SPHardwareDataType | /usr/bin/awk '/Hardware UUID:/ { print $3 }')
extAttName=""LAPS""

LAPS_Password=$(curl -s -f -u $apiUser:$apiPass -H "Accept: application/xml" $apiURL/JSSResource/computers/udid/$udid/subset/extension_attributes | xpath "//extension_attribute[name=$extAttName]" 2>&1 | awk -F'<value>|</value>' '{print $2}')

echo $LAPS_Password

Does anyone know what may be going wrong here?

Best answer by sim_brar

Update: It turns out that the API password "apiPass" was too complex (i.e. alphanumeric) for the script (seen here also: https://www.jamf.com/jamf-nation/discussions/27059/api-authentication-doesn-t-work). Simplifying the password resolved the issue.

View original
Did this topic help you find an answer to your question?

4 replies

Forum|alt.badge.img+7
  • Author
  • Contributor
  • 12 replies
  • Answer
  • October 2, 2019

Update: It turns out that the API password "apiPass" was too complex (i.e. alphanumeric) for the script (seen here also: https://www.jamf.com/jamf-nation/discussions/27059/api-authentication-doesn-t-work). Simplifying the password resolved the issue.


Forum|alt.badge.img+6
  • Contributor
  • 73 replies
  • March 25, 2021

@sim.brar Did you ever come across this? I copied your script line for line and changed only the EA name and credentials to match mine.

apiURL=$(/usr/bin/defaults read /Library/Preferences/com.jamfsoftware.jamf.plist jss_url | sed 's|/$||')
udid=$(/usr/sbin/system_profiler SPHardwareDataType | /usr/bin/awk '/Hardware UUID:/ { print $3 }')
extAttName=""UserCN""

LAPS_Password=$(curl -s -f -u $apiUser:$apiPass -H "Accept: application/xml" $apiURL/JSSResource/computers/udid/$udid/subset/extension_attributes | xpath "//extension_attribute[name=$extAttName]" 2>&1 | awk -F'<value>|</value>' '{print $2}')

echo UserCN: $LAPS_Password



Forum|alt.badge.img+1
  • New Contributor
  • 4 replies
  • March 26, 2021

Hi djrory,

I was encountering the same issue on a script running fine from a while.

The issue is coming from Big Sur : Dealing with xpath changes in Big Sur

Hope this helps...


Forum|alt.badge.img+7
  • Author
  • Contributor
  • 12 replies
  • March 27, 2021

@djrory @marc.beuvin yup, please see the same script, updated for Big Sur:

#!/bin/bash

apiUser=""
apiPass=""
apiURL=$(/usr/bin/defaults read /Library/Preferences/com.jamfsoftware.jamf.plist jss_url | sed 's|/$||')
udid=$(/usr/sbin/system_profiler SPHardwareDataType | /usr/bin/awk '/Hardware UUID:/ { print $3 }')
extAttName=""LAPS""

LAPS_Password=$(curl -s -f -u $apiUser:$apiPass -H "Accept: application/xml" $apiURL/JSSResource/computers/udid/$udid/subset/extension_attributes | xpath -e "//extension_attribute[name=$extAttName]" 2>&1 | awk -F'<value>|</value>' '{print $2}' | tail -n +1)

echo $LAPS_Password

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings