Linux get the list of FC HBA’s and WWPN

This simple script gives you the list of FC HBA detected in system. It query the sysfs filesystem to get the available fibre channel HBA. Script works for most of the Linux flavors, as specially any of Redhat, SUSE, Fedora and Centos distributions.

This script will not alter any of system configuration rather it just query the sysfs filesystem. Copy the script to server and execute it. Output collected under file “/tmp/hba_list.txt”.

Note

This script will not list the HBA if there is any hardware or driver issue. In such case refer “dmesg“ to troubleshoot further.

 

#!/bin/bash
#
# Display available FC Ports and their WWPN
echo "--------------------------------------------------"
echo -e "\tCollecting the available HBA details. \n\tOutput stored as /tmp/hba_list.txt"
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`
cat << EOB >> /tmp/hba_list.txt

FC-Host: $FC_HOST
---------------------------------------------------------------------------
HBA WWPN : $wwpn PortId: $PortID
HBA State: $state Speed : $speed
EOB
done

Here is the sample of HBA details which has been collected by above script.

#cat /tmp/hba_list.txt

FC-Host: host1
---------------------------------------------------------------------------
HBA WWPN : 0x5001439994c99988 PortId: 0x100300
HBA State: Online Speed : 4 Gbit

FC-Host: host2
---------------------------------------------------------------------------
HBA WWPN : 0x5001439994c9998a PortId: 0x0f0300
HBA State: Online Speed : 4 Gbit
Attachments
There are no attachments for this article.
Related Articles RSS Feed
awk printf
Viewed 15519 times since Wed, Aug 19, 2020
HowTo: Find Out Hard Disk Specs / Details on Linux
Viewed 3684 times since Mon, Jan 28, 2019
ubuntu How to Reset Forgotten Root Password in Ubuntu
Viewed 3076 times since Tue, Dec 8, 2020
YUM CRON Enabling automatic updates in Centos 7 and RHEL 7
Viewed 12066 times since Fri, Oct 26, 2018
Using etckeeper with git
Viewed 7040 times since Sun, Jun 3, 2018
SSH ProxyCommand example: Going through one host to reach another server
Viewed 13833 times since Tue, Aug 6, 2019
OpenSSL – sprawdzanie czy klucz pasuje do certyfikatu
Viewed 2817 times since Thu, May 24, 2018
LVM: Extend an existing Volume Group by adding a new disk
Viewed 2191 times since Sat, Jun 2, 2018
Terminal based "The Matrix" like implementation
Viewed 2412 times since Thu, Apr 18, 2019
Linux / UNIX: DNS Lookup Command
Viewed 9727 times since Sun, Sep 30, 2018