1#!/bin/sh 2 3IBPATH=${IBPATH:-@IBSCRIPTPATH@} 4 5function usage() { 6 echo Usage: `basename $0` "[-h] [<topology-file> | -C ca_name" \ 7 "-P ca_port -t(imeout) timeout_ms]" 8 exit -1 9} 10 11topofile="" 12ca_info="" 13 14while [ "$1" ]; do 15 case $1 in 16 -h) 17 usage 18 ;; 19 -P | -C | -t | -timeout) 20 case $2 in 21 -*) 22 usage 23 ;; 24 esac 25 if [ x$2 = x ] ; then 26 usage 27 fi 28 ca_info="$ca_info $1 $2" 29 shift 30 ;; 31 -*) 32 usage 33 ;; 34 *) 35 if [ "$topofile" ]; then 36 usage 37 fi 38 topofile="$1" 39 ;; 40 esac 41 shift 42done 43 44if [ "$topofile" ]; then 45 netcmd="cat $topofile" 46else 47 netcmd="$IBPATH/ibnetdiscover $ca_info" 48fi 49 50text="`eval $netcmd`" 51rv=$? 52echo "$text" | awk ' 53/^Switch/ { 54 l=$0 55 desc=substr(l, match(l, "#[ \t]*")+RLENGTH) 56 pi=match(desc, "port 0.*") 57 pinfo=substr(desc, pi) 58 desc=substr(desc, 1, pi-2) 59 type="base" 60 ti=match(desc, type) 61 if (ti==0) { 62 type="enhanced" 63 ti=match(desc, type) 64 if (ti!=0) 65 desc=substr(desc, 1, ti-2) 66 } else 67 desc=substr(desc, 1, ti-2) 68 if (ti==0) 69 print $1 "\t: 0x" substr($3, 4, 16) " ports " $2 " "\ 70 desc " " pinfo 71 else 72 print $1 "\t: 0x" substr($3, 4, 16) " ports " $2 " "\ 73 desc " " type " " pinfo} 74/^ib/ {print $0; next} 75/ibpanic:/ {print $0} 76/ibwarn:/ {print $0} 77/iberror:/ {print $0} 78' 79exit $rv 80