Posted on 01-27-2015 11:06 AM
I'm working on a script that would be used while a device is in the Netboot state. The script will remove the device from the JSS and Active Directory then format the HD.
The part i'm hoping someone can assist with is how to get the Computer Name based on the UUID. I'm getting the UUID with the following script.
uuid=$(/usr/sbin/ioreg -rd1 -c IOPlatformExpertDevice | /usr/bin/grep -i "UUID" | /usr/bin/cut -c27-62)
I'm hoping this is possible so i can avoid having to prompt the tech for the device name.
Solved! Go to Solution.
Posted on 01-27-2015 11:25 AM
Yes, its possible. Here's the syntax I would use
/usr/bin/curl -H "Accept: application/xml" -sfku "${apiuser}:${apipass}" https://yourjss.com:8443/JSSResource/computers/udid/${uuid} | xpath /computer/general/name[1] | awk -F'>|<' '/name/{print $3}'
BTW, in the JSS, its actually referred to as the UDID, not UUID, but the info you're grabbing is correct for the curl command. Also, here is a slightly more efficient way to get the UUID/UDID.
/usr/sbin/ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"' '/IOPlatformUUID/{print $4}'
Posted on 01-27-2015 12:56 PM
I agree with @mm2270][/url][/url, but my solution would work a little different.
#!/bin/sh
########################################################################
# User changable settings...
########################################################################
jssUser='username'
jssPass='password'
jssHost=https://jssurl.com:8443/
########################################################################
# Code below
########################################################################
OSVersion=$(sw_vers -productVersion)
uuid=$( /usr/sbin/system_profiler -xml SPHardwareDataType | /usr/bin/xpath "//array/dict/array/dict/string[preceding-sibling::key='platform_UUID'][1]/text()" 2> /dev/null )
xmlComputerInfo="<?xml version="1.0" encoding="ISO-8859-1" ?>
<computer>
</computer>"
theJSSresponse=$( /usr/bin/curl
--header "Content-Type: text/xml; charset=utf-8"
--data "${xmlComputerInfo}"
--request GET
--connect-timeout 5
--max-time 10
--user ${jssUser}:${jssPass}
${jssHost}JSSResource/computers/udid/${uuid} 2> /dev/null )
computerName=`echo $theJSSResponse | xpath /computer/general/name[1] | awk -F'>|<' '/name/{print $3}'`
*Note* I have not tested to code. You might need to change some things to make it work for you.
Hope either one of these helps.
Posted on 01-27-2015 11:25 AM
Yes, its possible. Here's the syntax I would use
/usr/bin/curl -H "Accept: application/xml" -sfku "${apiuser}:${apipass}" https://yourjss.com:8443/JSSResource/computers/udid/${uuid} | xpath /computer/general/name[1] | awk -F'>|<' '/name/{print $3}'
BTW, in the JSS, its actually referred to as the UDID, not UUID, but the info you're grabbing is correct for the curl command. Also, here is a slightly more efficient way to get the UUID/UDID.
/usr/sbin/ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"' '/IOPlatformUUID/{print $4}'
Posted on 01-27-2015 12:56 PM
I agree with @mm2270][/url][/url, but my solution would work a little different.
#!/bin/sh
########################################################################
# User changable settings...
########################################################################
jssUser='username'
jssPass='password'
jssHost=https://jssurl.com:8443/
########################################################################
# Code below
########################################################################
OSVersion=$(sw_vers -productVersion)
uuid=$( /usr/sbin/system_profiler -xml SPHardwareDataType | /usr/bin/xpath "//array/dict/array/dict/string[preceding-sibling::key='platform_UUID'][1]/text()" 2> /dev/null )
xmlComputerInfo="<?xml version="1.0" encoding="ISO-8859-1" ?>
<computer>
</computer>"
theJSSresponse=$( /usr/bin/curl
--header "Content-Type: text/xml; charset=utf-8"
--data "${xmlComputerInfo}"
--request GET
--connect-timeout 5
--max-time 10
--user ${jssUser}:${jssPass}
${jssHost}JSSResource/computers/udid/${uuid} 2> /dev/null )
computerName=`echo $theJSSResponse | xpath /computer/general/name[1] | awk -F'>|<' '/name/{print $3}'`
*Note* I have not tested to code. You might need to change some things to make it work for you.
Hope either one of these helps.
Posted on 01-27-2015 01:10 PM
I really appreciate the reply's however when running either code i get the following error...
no element found at line 2, column 0, byte 1: ^ at /System/Library/Perl/Extras/5.18/darwin-thread-multi-2level/XML/Parser.pm line 187.
Posted on 01-27-2015 01:25 PM
@Potter][/url][/url that is xpath not parsing out the xml properly. what you need to do is just echo out the "theJSSresponse" and see what you need to work with path.
Here is a bit dirtier of markup of the xpath parse.
echo $theJSSresponse | xpath /computer/general/name[1] | sed 's/<name>//g' | sed 's/</name>//g'
I did test the whole script this time, and I can say it does work.
Posted on 01-29-2015 07:26 AM