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
Kernel sysctl configuration file for Linux
Viewed 6339 times since Fri, Aug 3, 2018
Transform XML to CSV Format | Unix String Pattern Manipulation The Ugly Way
Viewed 8022 times since Sun, Jan 9, 2022
RHEL7: Configure automatic updates.
Viewed 2625 times since Wed, Oct 17, 2018
stunnel Securing telnet connections with stunnel
Viewed 2409 times since Sun, Dec 6, 2020
Linux RAID Mdadm Cheat Sheet
Viewed 6501 times since Fri, May 15, 2020
LVM: Reduce an existing Logical Volume / Filesystem
Viewed 4295 times since Sat, Jun 2, 2018
ZFS: Remove an existing zfs filesystem
Viewed 2804 times since Sun, Jun 3, 2018
How to disable SSH cipher/ MAC algorithms for Linux and Unix
Viewed 51123 times since Fri, Aug 21, 2020
Red Hat 8 How to Set Up Automatic Updates for CentOS 8
Viewed 4911 times since Fri, Sep 25, 2020
SSH ProxyCommand example: Going through one host to reach another server
Viewed 15032 times since Tue, Aug 6, 2019