Search code examples
xmlmacosxml-parsingplistxmllint

OSX Parsing system_profiler- Fibre card info


I would like to extract just the keys. I tried using plistbuddy and xmllint --xpath but seem to get the right combination. I can't do a simple grep for "spfibrechannel_portworldwidename" because this shows up many time. I have to be able to identify this using the xml position.

spfibrechannel_portworldwidename 24:01:00:01:55:5B:67:5A

spfibrechannel_portworldwidename 24:02:00:01:55:5B:67:5A

enter image description here

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
    <dict>
        <key>_SPCommandLineArguments</key>
        <array>
            <string>/usr/sbin/system_profiler</string>
        </array>
        <key>_SPCompletionInterval</key>
        <real>0.4425880312919617</real>
        <key>_SPResponseTime</key>
        <real>0.5688720345497131</real>
        <key>_dataType</key>
        <string>SPFibreChannelDataType</string>
        <key>_detailLevel</key>
        <integer>-1</integer>
        <key>_items</key>
        <array>
            <dict>
                <key>_items</key>
                <array>
                    <dict>
                        <key>_items</key>
                        <array>
                            <dict>
                                <key>_name</key>
                                <string>SCSI Logical Unit @ 5</string>
                                <key>bsd_name</key>
                                <string>disk6</string>
                                <key>detachable_drive</key>
                                <string>no</string>
                                <key>device_manufacturer</key>
                                <string>NEXSAN</string>
                                <key>device_model</key>
                                <string>NXS-B01-000</string>
                                <key>device_revision</key>
                                <string>R011</string>
                                <key>partition_map_type</key>
                                <string>unknown_partition_map_type</string>
                                <key>removable_media</key>
                                <string>yes</string>
                                <key>size</key>
                                <string>17.82 TB</string>
                                <key>size_in_bytes</key>
                                <integer>17816837947392</integer>
                                <key>smart_status</key>
                                <string>Not Supported</string>
                                <key>spfibrechannel_alua_support</key>
                                <string>Implicit</string>
                                <key>spfibrechannel_load_balancing_algorithm</key>
                                <string>Least Bytes</string>
                                <key>spfibrechannel_logical_unit_access_state</key>
                                <string>Active Non-Optimized</string>
                                <key>spfibrechannel_logical_unit_unique_id</key>
                                <string>0x6000402005E01DD678BD626000000000</string>
                                <key>spfibrechannel_lun</key>
                                <string>00:05:00:00:00:00:00:00</string>
                            </dict>
                        </array>
                        <key>_name</key>
                        <string>SCSI Target Device @ 0</string>
                        <key>device_manufacturer</key>
                        <string>NEXSAN</string>
                        <key>device_model</key>
                        <string>NXS-B01-000</string>
                        <key>device_revision</key>
                        <string>R011</string>
                        <key>spfibrechannel_addressidentifier</key>
                        <string>03:00:00</string>
                        <key>spfibrechannel_device_type</key>
                        <integer>0</integer>
                        <key>spfibrechannel_nodeworldwidename</key>
                        <string>20:05:00:04:02:E7:1D:D6</string>
                        <key>spfibrechannel_portworldwidename</key>
                        <string>50:00:40:20:05:E7:1D:D6</string>
                        <key>spfibrechannel_target</key>
                        <string>0</string>
                    </dict>
                </array>
                <key>_name</key>
                <string>Fibre Channel Domain 4</string>
                <key>spfibrechannel_addressidentifier</key>
                <string>01:00:00</string>
                <key>spfibrechannel_cablingtype</key>
                <string>Fiber Optic</string>
                <key>spfibrechannel_initiatorid</key>
                <integer>3791655135</integer>
                <key>spfibrechannel_nodeworldwidename</key>
                <string>23:00:00:01:55:5B:67:5A</string>
                <key>spfibrechannel_portdescription</key>
                <string>Port 0</string>
                <key>spfibrechannel_portspeed</key>
                <string>4 Gigabit</string>
                <key>spfibrechannel_portstatus</key>
                <string>Link Established</string>
                <key>spfibrechannel_porttopology</key>
                <string>Automatic (N_Port)</string>
                <key>spfibrechannel_portworldwidename</key>
                <string>24:01:00:01:55:5B:67:AA</string>
                <key>spfibrechannel_product</key>
                <string>SANLINK 2</string>
                <key>spfibrechannel_revision</key>
                <string>Firmware 1.1.58.0 Hardware b</string>
                <key>spfibrechannel_vendor</key>
                <string>Promise</string>
            </dict>
            <dict>
                <key>_items</key>
                <array>
                    <dict>
                        <key>_items</key>
                        <array>
                            <dict>
                                <key>_name</key>
                                <string>SCSI Logical Unit @ 5</string>
                                <key>bsd_name</key>
                                <string>disk6</string>
                                <key>detachable_drive</key>
                                <string>no</string>
                                <key>device_manufacturer</key>
                                <string>NEXSAN</string>
                                <key>device_model</key>
                                <string>NXS-B01-000</string>
                                <key>device_revision</key>
                                <string>R011</string>
                                <key>partition_map_type</key>
                                <string>unknown_partition_map_type</string>
                                <key>removable_media</key>
                                <string>yes</string>
                                <key>size</key>
                                <string>17.82 TB</string>
                                <key>size_in_bytes</key>
                                <integer>17816837947392</integer>
                                <key>smart_status</key>
                                <string>Not Supported</string>
                                <key>spfibrechannel_alua_support</key>
                                <string>Implicit</string>
                                <key>spfibrechannel_load_balancing_algorithm</key>
                                <string>Least Bytes</string>
                                <key>spfibrechannel_logical_unit_access_state</key>
                                <string>Active Non-Optimized</string>
                                <key>spfibrechannel_logical_unit_unique_id</key>
                                <string>0x6000402005E01DD678BD626000000000</string>
                                <key>spfibrechannel_lun</key>
                                <string>00:05:00:00:00:00:00:00</string>
                            </dict>
                        </array>
                        <key>_name</key>
                        <string>SCSI Target Device @ 0</string>
                        <key>device_manufacturer</key>
                        <string>NEXSAN</string>
                        <key>device_model</key>
                        <string>NXS-B01-000</string>
                        <key>device_revision</key>
                        <string>R011</string>
                        <key>spfibrechannel_addressidentifier</key>
                        <string>03:00:00</string>
                        <key>spfibrechannel_device_type</key>
                        <integer>0</integer>
                        <key>spfibrechannel_nodeworldwidename</key>
                        <string>20:05:00:04:02:E7:1D:D6</string>
                        <key>spfibrechannel_portworldwidename</key>
                        <string>50:00:40:20:05:E7:1D:D6</string>
                        <key>spfibrechannel_target</key>
                        <string>0</string>
                    </dict>
                </array>
                <key>spfibrechannel_initiatorid</key>
                <integer>3791655135</integer>
                <key>spfibrechannel_nodeworldwidename</key>
                <string>23:00:00:01:55:5B:67:5A</string>
                <key>spfibrechannel_portdescription</key>
                <string>Port 1</string>
                <key>spfibrechannel_portspeed</key>
                <string>4 Gigabit</string>
                <key>spfibrechannel_portstatus</key>
                <string>Link Established</string>
                <key>spfibrechannel_porttopology</key>
                <string>Automatic (N_Port)</string>
                <key>spfibrechannel_portworldwidename</key>
                <string>24:02:00:01:55:5B:67:5A</string>
                <key>spfibrechannel_product</key>
                <string>SANLINK 2</string>
                <key>spfibrechannel_revision</key>
                <string>Firmware 1.1.58.0 Hardware b</string>
                <key>spfibrechannel_vendor</key>
                <string>Promise</string>
            </dict>
        </array>
        <key>_versionInfo</key>
        <dict>
            <key>com.apple.SystemProfiler.SPFibreChannelReporter</key>
            <string>2.1.1</string>
        </dict>
    </dict>
</array>
</plist>

Solution

  • Solved by a different approach...

    system_profiler SPFibreChannelDataType | grep -A 9 "Fibre Channel Domain [0-9]" |grep "Port World Wide Name" |awk '{print $5}' | sed -n '1p'