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
20 Practical Examples of RPM Commands in Linux rpm
Viewed 7765 times since Mon, Feb 18, 2019
VMWare tools free
Viewed 8217 times since Mon, Jul 16, 2018
A Quick and Practical Reference for tcpdump
Viewed 12285 times since Fri, Jul 27, 2018
HowTo: Send Email from an SMTP Server using the Command Line
Viewed 1711 times since Mon, Feb 18, 2019
How do I add ethtool settings to a network device permanently?
Viewed 6359 times since Mon, May 21, 2018
OpenSSL: Check SSL Certificate Expiration Date and More
Viewed 6468 times since Mon, Feb 18, 2019
Linux File Systems (mkfs, mount, fstab) ext4
Viewed 3006 times since Sat, Jun 2, 2018
Linux How to reset a root password on Fedora
Viewed 2300 times since Sun, Dec 6, 2020
Linux Proxy Server Settings – Set Proxy For Command Line
Viewed 3034 times since Mon, Feb 18, 2019
Using grep to find string in files
Viewed 1940 times since Fri, May 15, 2020