Skip to main content

Hey Guys,



I am trying to get the serial number of our thunderbolt docks with ioreg or system_profiler to have an extension attribute for the docks in Casper.



So far I got this



$ system_profiler SPThunderboltDataType

Thunderbolt:

Thunderbolt Bus:

Vendor Name: Apple Inc.
Device Name: MacBook Pro
UID: 0x0001000F01673350
Firmware Version: 17,2
Domain UUID: 3F75FB1E-3A50-C95C-B5FC-0FF493EC3B19
Port:
Status: Device connected
Link Status: 0x2
Current Link Width: 0x2
Receptacle: 1
Cable Firmware Version: 1.0.16
Cable Serial Number: C4M435600SSF797A5
Link Controller Firmware Version: 0.11.0
Port:
Status: No device connected
Link Status: 0x7
Current Link Width: 0x1
Receptacle: 2
Link Controller Firmware Version: 0.11.0

Thunderbolt 2 Express Dock HD:

Vendor Name: Belkin International, Inc.
Device Name: Thunderbolt 2 Express Dock HD
Vendor ID: 0x13
Device ID: 0x85
Device Revision: 0x1
UID: 0x001314414033FB00
Route String: 1
Firmware Version: 25,1
Port (Upstream):
Status: Device connected
Link Status: 0x2
Current Link Width: 0x2
Cable Firmware Version: 1.0.16
Cable Serial Number: C4M435600SSF797A5
Link Controller Firmware Version: 0.14.0
Port:
Status: No device connected
Link Status: 0x7
Current Link Width: 0x1
Link Controller Firmware Version: 0.14.0


I know that the Serial number is the UID underneath "Thunderbolt 2 Express Dock HD:"
UID: 0x001314414033FB00



I'm not really good with grep or awk to get just the serial number which starts with 1314... wouldn't mind the 00 in front of it. But right now I also get the other UID of the mac if I use grep...



$system_profiler SPThunderboltDataType | grep " UID: "

UID: 0x0001000F01673350
UID: 0x001314414033FB00


Any idea how to get that done?



Bear with me, I'm new to this :-D



Lenny

Can you run this command and post the output?



system_profiler SPThunderboltDataType -xml | awk '/<array>/,/</array>/{print}'


You may have better luck getting the right information by piping it into an xml format first, but I can't tell since I don't have a Thunderbolt dock. Unless you want to send me one to test with? :-D


Thanks!



This is the output:



<array>
<dict>
<key>_SPCommandLineArguments</key>
<array>
<string>/usr/sbin/system_profiler</string>
<string>-nospawn</string>
<string>-xml</string>
<string>SPThunderboltDataType</string>
<string>-detailLevel</string>
<string>full</string>
</array>
<array>
<dict>
<key>_items</key>
<array>
<dict>
<key>_name</key>
<string>Thunderbolt 2 Express Dock HD</string>
<key>device_id_key</key>
<string>0x85</string>
<key>device_name_key</key>
<string>Thunderbolt 2 Express Dock HD</string>
<key>device_revision_key</key>
<string>0x1</string>
<key>receptacle_2_tag</key>
<dict>
<key>current_link_width_key</key>
<string>0x1</string>
<key>lc_version_key</key>
<string>0.14.0</string>
<key>link_status_key</key>
<string>0x7</string>
<key>receptacle_status_key</key>
<string>receptacle_no_devices_connected</string>
</dict>
<key>receptacle_upstream_ambiguous_tag</key>
<dict>
<key>cm_asn_key</key>
<string>C4M435600SSF797A5</string>
<key>cm_version_key</key>
<string>1.0.16</string>
<key>current_link_width_key</key>
<string>0x2</string>
<key>lc_version_key</key>
<string>0.14.0</string>
<key>link_status_key</key>
<string>0x2</string>
<key>receptacle_status_key</key>
<string>receptacle_connected</string>
</dict>
<key>route_string_key</key>
<string>1</string>
<key>switch_uid_key</key>
<string>0x001314414033FB00</string>
<key>switch_version_key</key>
<string>25.1</string>
<key>vendor_id_key</key>
<string>0x13</string>
<key>vendor_name_key</key>
<string>Belkin International, Inc.</string>
</dict>
</array>


I really would like to send you one, but I think my boss doesn't want to :-D


#!/bin/bash

## This makes a bunch of assumptions

checkme=0
tbdock="Thunderbolt 2 Express Dock HD:"

system_profiler SPThunderboltDataType | while read line
do
if [[ "$line" =~ "$tbdock" ]]
then
checkme=1
fi

if [ $checkme -eq 1 ] && [[ "$line" =~ "UID:" ]]
then
echo "$tbdock ${line##* }"
checkme=0
fi
done

exit 0

This Script gives the output:
Thunderbolt 2 Express Dock HD: 0x001314414033FB00



Thank you for that!



Is it also possible to cut the "0x"?


echo "$tbdock ${line##* }" | sed 's/0x//g'

Perfect!



Just what I needed. It works like a charm!


Reply