Hey Jamf guys and gals!
I am trying to query information from our JAMF Pro server through the API. I'm like halfway there but I definitely don't know what I am doing completely.
The name scheme we want to do is "(first 4 or 5 characters of the building)-(JAMF ID #)" . I am able to query both of those pieces of information through a script that calls the API, however I can't seem to get the "cut" command to take the first 4 or 5 characters of the building information. Any information on how to cut up the building information would be so helpful. This is what I have so far:
#!/bin/bash
apiuser=$4
apipass=$5
jssurl=https://myjamf.com
serial=$(/usr/sbin/ioreg -rd1 -c IOPlatformExpertDevice | /usr/bin/awk -F'"' '/IOPlatformSerialNumber/{print $4}')
computerID=$(/usr/bin/curl -u $apiuser:$apipass $jssurl:8443/JSSResource/computers/serialnumber/$serial -H "accept: text/xml" | /usr/bin/xpath -e "/computer/general/id/text()")
location=$(/usr/bin/curl -u $apiuser:$apipass $jssurl:8443/JSSResource/computers/serialnumber/$serial -H "accept: text/xml" | /usr/bin/xpath -e "/computer/location/building/text()")
If I echo the location information, it does spit out the full building name. If I try to use it like this, it doesn't echo any information anymore:
location=$(/usr/bin/curl -u $apiuser:$apipass $jssurl:8443/JSSResource/computers/serialnumber/$serial -H "accept: text/xml" | /usr/bin/xpath -e "/computer/location/building/text()") | cut -b 1-4
At the end once I get the string, I'm sure I'll us scutil to rename the computer and disconfigad to bind to AD, but I need help getting this first part done.
Thanks for taking the time to read if you did.