Wednesday, May 13, 2020

HBA Info Script

I thought I would pass this script along for anyone needing a way to out HBA info on Linux in a nicely formatted table.

#!/bin/bash
echo "FC_HOST     |   PortID   |    WWN             | State      | Speed    "
echo "------------+------------+--------------------+------------+----------"
for hba in `ls -d /sys/class/fc_host/host*`;do
  FC_HOST=`basename $hba`
  PortID=`cat $hba/port_id`
  wwpn=`cat $hba/port_name`
  state=`cat $hba/port_state`
  speed=`cat $hba/speed`
  hba=`cat $hba/symbolic_name`
  echo "$FC_HOST| $PortID | $wwpn | $state| $speed" | awk 'BEGIN{OFS=FS="|"}{for(i=1;i<=NF;i++){$i=sprintf("%-12s",$i)};print}'
done #|sort -k3n,6
echo "------------+------------+--------------------+------------+----------"


The output looks like this


FC_HOST     |   PortID   |    WWN             | State      | Speed    
------------+------------+--------------------+------------+----------
host0       | 0xffffffff | 0x20003890a540876c | Linkdown   | unknown  
host11      | 0xffffffff | 0x20003890a540876d | Linkdown   | unknown  
host12      | 0x640000   | 0x100000109b1bbe00 | Online     | 32 Gbit  
host13      | 0xffffffff | 0x20003890a5803461 | Linkdown   | 40 Gbit  
host14      | 0xffffffff | 0x20003890a5803462 | Linkdown   | 40 Gbit  
host15      | 0x640000   | 0x100000109b1bbe01 | Online     | 32 Gbit  
host16      | 0x03eac0   | 0x100000109b1b9a77 | Online     | 16 Gbit  
host17      | 0x04eac0   | 0x100000109b1b9a78 | Online     | 16 Gbit  
------------+------------+--------------------+------------+----------

If you would like more detail I added a couple more columns to show make, model, firmware, and driver version. This is a fixed width column layout and the minimum column width can be adjusted for your needs.

#!/bin/bash
echo "FC_HOST         |   PortID       |    WWN             | State          | Speed          | Make           | Model          | Firmware       | Driver"
echo "----------------+----------------+--------------------+----------------+----------------+----------------+----------------+----------------+---------------"
for hba in `ls -d /sys/class/fc_host/host*`;do
  FC_HOST=`basename $hba`
  PortID=`cat $hba/port_id`
  wwpn=`cat $hba/port_name`
  state=`cat $hba/port_state`
  speed=`cat $hba/speed`
  hba=`cat $hba/symbolic_name`
  hba_make=`echo $hba | cut -f1 -d ' ' `
  hba_model=`echo $hba | cut -f2 -d ' ' `
  hba_fw=`echo $hba | cut -f3 -d ' ' `
  hba_driver=`echo $hba | cut -f4 -d ' ' `
  echo "$FC_HOST| $PortID | $wwpn | $state| $speed | $hba_make | $hba_model | $hba_fw | $hba_driver " | awk 'BEGIN{OFS=FS="|"}{for(i=1;i<=NF;i++){$i=sprintf("%-16s",$i)};print}'
done #|sort -k3n,6

echo "----------------+----------------+--------------------+----------------+----------------+----------------+----------------+----------------+---------------"

The output looks similar to this:



No comments:

Post a Comment