Find out which port wwn is connected to

This script was written to find out the port on a Brocade FC switch which a server port is patched to, knowing the wwn of the server fc port.

You will need to add the switch names (not FQDN) into the for SWITCH in part, they will meed to be resolvable in DNS when added to the Domain name. Also, you will need to set the SNMP community string for the switches. It assumes the community string is the same for all switches.

Very few assumptions are made on the format of the submitted wwn, so all these formats will work:- 0x50014380140f06fa, 50:01:43:80:14:0f:06:fa or 5001-4380-140f-06fa.

#!/bin/bash
#$ snmpwalk -v1 -c public fcsw1-02.prod.int.com | grep -i "50 01 43 80 14 0f 01 b4"
#SNMPv2-SMI::mib-2.75.1.2.3.1.10.1.4.1 = Hex-STRING: 50 01 43 80 14 0F 01 B6
#$ echo $?
#0
#$ snmpwalk -v1 -c public fcsw2-02.prod.int.com | grep -i "50 01 43 80 14 0f 01 b6"
#$ echo $?
#1
SNMPPASS="public"
DOMAIN="yourdomain.com"

OUTFILE=wwnport.txt-$$
export SNMPPASS OUTFILE

INPUTWWN=$@
echo "Searching for >${INPUTWWN}<"

if [ "${INPUTWWN}" = '' ]
 then
   echo "You need to provide a WWN number, eg. 0x50014380140f06fa, 50:01:43:80:14:0f:06:fa or 5001-4380-140f-06fa"
fi

if [[ $INPUTWWN =~ 0x ]]
then
        #remove 0x and add spaces
        #echo "Removing 0x and adding spaces"
        INPUTWWNtmp1=`echo ${INPUTWWN} | cut -dx -f2 | sed 's/../& /g' `
        INPUTWWN=${INPUTWWNtmp1}
        #echo "Input WWN is ${INPUTWWN}"

elif [[ $INPUTWWN =~ : ]]
then
        #remove colons and replace with space
        #echo "Replacing : with space"
        INPUTWWNtmp2=`echo ${INPUTWWN} | sed 's/:/ /g'`
        INPUTWWNtmp3=`echo ${INPUTWWNtmp2} | sed 's/../& /g' `
        INPUTWWN=${INPUTWWNtmp3}
        #echo "Input WWN is ${INPUTWWN}"

elif [[ $INPUTWWN =~ - ]]
then
        #remove hyphen then add spaces
        #echo "Removing -"
        INPUTWWNtmp2=`echo ${INPUTWWN} | sed 's/-//g'`
        #echo "Adding spaces"
        INPUTWWNtmp3=`echo ${INPUTWWNtmp2}| sed 's/../& /g' `
        INPUTWWN=${INPUTWWNtmp3}
        #echo "Input WWN is ${INPUTWWN}"


elif [[ $INPUTWWN =~ " " ]]
then
        #Already have spaces
        DUMMY=true
        #echo "String already has spaces"
        #echo "Input WWN is ${INPUTWWN}"

else
        #Format not supported
        echo "Input format not supported, exiting."
        exit 1
fi


for SWITCH in fcsw1-01 fcsw2-01 fcsw1-02 fcsw2-02 fcsw1-03 fcsw2-03 fcsw1-04 fcsw2-04;
do
        #echo "Testing ${SWITCH}"
        snmpwalk -v1 -c ${SNMPPASS} ${SWITCH}.${DOMAIN} mib-2.75.1.2.3.1.10 | grep -i "${INPUTWWN}" > ${OUTFILE}

        RESULT1=`echo $?`
        #echo $RESULT1

        if [ "${RESULT1}" = "0" ]
         then
           WWNPORTTMP1=`cat ${OUTFILE} |  cut -d. -f9`
           ((WWNPORT=(WWNPORTTMP1-1) ))
           echo "WWN ${INPUTWWN} found on switch ${SWITCH} on port ${WWNPORT}."
        fi


        #echo "=============================="
done

#clean up
rm ${OUTFILE}

exit 0
 
rb/findwwnonswitch.txt · Last modified: 16/02/2015 13:03 by andrew