Posted on 10-11-2018 06:51 PM
I am looking for a way to query the API for the username of the Mac's assigned user in Jamf Pro.
Solved! Go to Solution.
Posted on 10-11-2018 08:08 PM
Here is a code snippet to get that info.
I use this snippet as part of a larger system renamer script.
#!/bin/sh
# Variables
jssURL="https://jamf.domain.com:8443/"
apiUser="apiuser"
apiPass="apipassword"
SERIAL=$(ioreg -c IOPlatformExpertDevice -d 2 | awk -F" '/IOPlatformSerialNumber/{print $(NF-1)}')
USERINFO=$(curl -k ${jssURL}JSSResource/computers/serialnumber/${SERIAL}/subset/location -H "Accept: application/xml" --user "${apiUser}:${apiPass}")
USERNAME=$(echo $USERINFO | /usr/bin/awk -F'<username>|</username>' '{print $2}' | tr [A-Z] [a-z])
first2user=$(echo ${USERNAME:0:2})
DEVICEINFO=$(curl -k ${jssURL}JSSResource/computers/serialnumber/${SERIAL}/subset/hardware -H "Accept: application/xml" --user "${apiUser}:${apiPass}")
MODEL=$(echo $DEVICEINFO | /usr/bin/awk -F'<model_identifier>|</model_identifier>' '{print $2}')
Posted on 10-11-2018 08:08 PM
Here is a code snippet to get that info.
I use this snippet as part of a larger system renamer script.
#!/bin/sh
# Variables
jssURL="https://jamf.domain.com:8443/"
apiUser="apiuser"
apiPass="apipassword"
SERIAL=$(ioreg -c IOPlatformExpertDevice -d 2 | awk -F" '/IOPlatformSerialNumber/{print $(NF-1)}')
USERINFO=$(curl -k ${jssURL}JSSResource/computers/serialnumber/${SERIAL}/subset/location -H "Accept: application/xml" --user "${apiUser}:${apiPass}")
USERNAME=$(echo $USERINFO | /usr/bin/awk -F'<username>|</username>' '{print $2}' | tr [A-Z] [a-z])
first2user=$(echo ${USERNAME:0:2})
DEVICEINFO=$(curl -k ${jssURL}JSSResource/computers/serialnumber/${SERIAL}/subset/hardware -H "Accept: application/xml" --user "${apiUser}:${apiPass}")
MODEL=$(echo $DEVICEINFO | /usr/bin/awk -F'<model_identifier>|</model_identifier>' '{print $2}')
Posted on 10-12-2018 05:31 AM
Thank you, thank you, thank you! I am just starting with Jamf Pro, so I appreciate your help!
Posted on 05-24-2020 09:32 PM
Just a small note tr [A-Z] [a-z] didn't work for me, but tr "A-Z" "a-z" worked. Without the double quotes works too.
USERNAME=$(echo $USERINFO | /usr/bin/awk -F'<username>|</username>' '{print $2}' | tr "A-Z" "a-z")