12-02-2022 09:28 AM - edited 12-02-2022 09:31 AM
What is the best way to try and debug an EA script? I’ve implemented logCollection https://github.com/kc9wwh/logCollection/wiki , and that works fine, but I’m trying to make a smart group that reports on Macs that have an attachment. The EA from https://github.com/kc9wwh/logCollection/wiki/Reporting doesn’t seem do anything. https://github.com/kc9wwh/logCollection/blob/master/EA-NumAttachments.sh shows... "jamfProURL="https://jamfpro.acme.net:8443"
I've tried that format, plus...
https://jamfpro.acme.net
https://jamfpro.acme.net/
...and none of those work (of course I'm using my own JPro instance address). Is there a log I can check to see where this is failing? Also, I know the api_user works, because that is the same user + creds that runs logCollection in the first place, and adds the attachment to the Mac.
Solved! Go to Solution.
12-02-2022 12:20 PM - edited 12-02-2022 12:21 PM
Notice the -e after xpath in OS > 11.
This should work. Replaces lines 10-14 from the original script. (Haven't tested)
osMajor=$(/usr/bin/sw_vers -productVersion | awk -F . '{print $1}')
osMinor=$(/usr/bin/sw_vers -productVersion | awk -F . '{print $2}')
## Determine Jamf Pro Device ID
if [[ "$osMajor" -ge 11 ]]; then
jamfProID=$( curl -k -u $jamfProUser:$jamfProPass $jamfProURL/JSSResource/computers/serialnumber/$mySerial/subset/general | xpath -e "//computer/general/id/text()" )
elif [[ "$osMajor" -eq 10 && "$osMinor" -gt 12 ]]; then
jamfProID=$( curl -k -u $jamfProUser:$jamfProPass $jamfProURL/JSSResource/computers/serialnumber/$mySerial/subset/general | xpath "//computer/general/id/text()" )
fi
## API Lookup for how many attachments are attached to this device record
if [[ "$osMajor" -ge 11 ]]; then
numAttachments=$( curl -u $jamfProUser:$jamfProPass $jamfProURL/JSSResource/computers/id/$jamfProID -X GET | xmllint -format - | xpath -e '/computer/purchasing/attachments' | grep "<id>" | wc -l | xargs )
elif [[ "$osMajor" -eq 10 && "$osMinor" -gt 12 ]]; then
numAttachments=$( curl -u $jamfProUser:$jamfProPass $jamfProURL/JSSResource/computers/id/$jamfProID -X GET | xmllint -format - | xpath '/computer/purchasing/attachments' | grep "<id>" | wc -l | xargs )
fi
Posted on 12-02-2022 11:31 AM
Take a look at the xpath parts on the EA. its only setup to work on older OS. If you look at the xpath on the script that uploads the logs, you can see the difference in xpath scheme for older and newer OS.
Posted on 12-02-2022 12:07 PM
hmmm, so the EA code is out of date. I tried change the xpath code from...
xpath '/computer/purchasing/attachments'
to
xpath "//computer/general/id/text()"
but now it just produces "parser error"s.
12-02-2022 12:20 PM - edited 12-02-2022 12:21 PM
Notice the -e after xpath in OS > 11.
This should work. Replaces lines 10-14 from the original script. (Haven't tested)
osMajor=$(/usr/bin/sw_vers -productVersion | awk -F . '{print $1}')
osMinor=$(/usr/bin/sw_vers -productVersion | awk -F . '{print $2}')
## Determine Jamf Pro Device ID
if [[ "$osMajor" -ge 11 ]]; then
jamfProID=$( curl -k -u $jamfProUser:$jamfProPass $jamfProURL/JSSResource/computers/serialnumber/$mySerial/subset/general | xpath -e "//computer/general/id/text()" )
elif [[ "$osMajor" -eq 10 && "$osMinor" -gt 12 ]]; then
jamfProID=$( curl -k -u $jamfProUser:$jamfProPass $jamfProURL/JSSResource/computers/serialnumber/$mySerial/subset/general | xpath "//computer/general/id/text()" )
fi
## API Lookup for how many attachments are attached to this device record
if [[ "$osMajor" -ge 11 ]]; then
numAttachments=$( curl -u $jamfProUser:$jamfProPass $jamfProURL/JSSResource/computers/id/$jamfProID -X GET | xmllint -format - | xpath -e '/computer/purchasing/attachments' | grep "<id>" | wc -l | xargs )
elif [[ "$osMajor" -eq 10 && "$osMinor" -gt 12 ]]; then
numAttachments=$( curl -u $jamfProUser:$jamfProPass $jamfProURL/JSSResource/computers/id/$jamfProID -X GET | xmllint -format - | xpath '/computer/purchasing/attachments' | grep "<id>" | wc -l | xargs )
fi
Posted on 12-02-2022 12:41 PM
That totally worked. I appreciate the assistance.