Utility script to collect HBA information on AIX

This is Sunny’s script to gather HBA information from AIX servers as follows:
# 12/04/2009 – created script to display hba WWN
# 07/06/2011 – Added logic to print disk and scsi id
# 10/01/2011 – Added logic to check NPIV and tape device
#
hba-info.sh
#
#!/usr/bin/ksh
#
#Script to print HBA WWN
#
#
cleanup() {
[[ -z "$1" ]] && echo "command at line ${1}\n"
rm -f $TMPFILE $TMPTAPE
exit
}
#
# Main start here
#
export PATH="/usr/bin:/etc:/usr/sbin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:$PATH:."
TMPFILE=/tmp/.hba-path.txt
TMPTAPE=/tmp/.tape.path.txt
trap 'cleanup $LINENO' QUIT EXIT INT
#
lspath > $TMPFILE
lsdev -Cc tape -F name,parent > $TMPTAPE
echo "Host Name, HBA, WWN, Location, Type, INIT_LINK, Attach, Dyntrk, fc_err_recov,SCSI ID,Usage,Slot"
#
lscfg -vl fcs*| perl -lane 'BEGIN { my @hbainfo; chomp($hostname=`hostname|cut -f1 -d. `) }
if(/^\s+(fcs\d+)\s+([^\s]+)(.*)$/){
$f=$1; $loc=$2; $adtype="REAL";
if ( $3 =~ /Virtual Fibre Channel/i ){ $adtype="NPIV";}
}
if(/Network/){
s/\s*Network Address\.+//; s/([\dA-F]{2})/$1:/g; s/:$//;
push( @hbainfo,sprintf("%s,%s,%s,%s,%s\n",$hostname,$f,$_,$loc,$adtype) );
}
END {
@shbainfo =sort { ($a =~ /(\d+)/)[0] ($b =~ /(\d+)/)[0] } @hbainfo;
foreach $h ( @shbainfo ) {
printf("%s", $h);
}
} ' | while read h
do
f=$( echo "$h" |perl -F',' -lapne '$_=$F[1]; s/fcs/fscsi/;' )
CARD=$( echo "$h" |cut -f2 -d,)
#
ATTACH=$(lsattr -El $f -a attach -F value)
DYNTRK=$(lsattr -El $f -a dyntrk -F value)
FCERRR=$(lsattr -El $f -a fc_err_recov -F value)
INIT_LINK=""
if ! $( echo "$h" |grep -qi "NPIV") ; then
INIT_LINK=$(lsattr -El $CARD -a init_link -F value)
fi
SCSI_ID=$(lsattr -El $f -a scsi_id -F value)

SLOT=$(lsdev -Cl $CARD|perl -lane 'print $F[2]')
CHILD="None"
DISKS=$(cat $TMPFILE |perl -slane 'BEGIN{$x=0;}if(/Enabled\s+.*$f$/){$x++;}END{print $x;}' -- -f=$f)
TAPE=$(cat $TMPTAPE |perl -slane 'BEGIN{$x=0;}if(/rmt\d+,$f$/){$x++;}END{print $x;}' -- -f=$f)
[ $DISKS -gt 0 ] && CHILD="DISK:$DISKS"
[ $TAPE -gt 0 ] && CHILD="TAPE:$TAPE"

echo "$h,$INIT_LINK,$ATTACH,$DYNTRK,$FCERRR,$SCSI_ID,$CHILD,$SLOT"
done

rm -f $TMPFILE $TMPTAPE
exit 0

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.