This is an old revision of the document!


Find out which port wwn is connected to

#!/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"
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}.prod.int.com 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.1401832432.txt.gz · Last modified: 03/06/2014 21:53 by andrew