1#!/bin/sh 2 3IBPATH=${IBPATH:-@IBSCRIPTPATH@} 4 5function usage() { 6 echo Usage: `basename $0` "[-h] [-b] [-v] [-N | -nocolor]"\ 7 "[<topology-file> | -C ca_name -P ca_port -t(imeout) timeout_ms]" 8 exit -1 9} 10 11function user_abort() { 12 echo "Aborted" 13 exit 1 14} 15 16trap user_abort SIGINT 17 18gflags="" 19verbose="" 20brief="" 21v=0 22ntype="" 23nodeguid="" 24topofile="" 25ca_info="" 26 27while [ "$1" ]; do 28 case $1 in 29 -h) 30 usage 31 ;; 32 -N|-nocolor) 33 gflags=-N 34 ;; 35 -v) 36 verbose=-v 37 brief="" 38 v=1 39 ;; 40 -b) 41 brief=-b 42 verbose="" 43 ;; 44 -P | -C | -t | -timeout) 45 case $2 in 46 -*) 47 usage 48 ;; 49 esac 50 if [ x$2 = x ] ; then 51 usage 52 fi 53 ca_info="$ca_info $1 $2" 54 shift 55 ;; 56 -*) 57 usage 58 ;; 59 *) 60 if [ "$topofile" ]; then 61 usage 62 fi 63 topofile="$1" 64 ;; 65 esac 66 shift 67done 68 69if [ "$topofile" ]; then 70 netcmd="cat $topofile" 71else 72 netcmd="$IBPATH/ibnetdiscover $ca_info" 73fi 74 75text="`eval $netcmd`" 76rv=$? 77echo "$text" | awk ' 78BEGIN { 79 ne=0 80} 81function check_node(lid, port) 82{ 83 if (system("'$IBPATH'/ibchecknode '"$ca_info"' '$gflags' '$verbose' " lid)) { 84 ne++ 85 print "\n# " ntype ": nodeguid 0x" nodeguid " failed" 86 return 1; 87 } 88 if (system("'$IBPATH'/ibcheckerrs '"$ca_info"' '$gflags' '$verbose' '$brief' " lid " " port)) 89 return 2; 90 return 0; 91} 92 93/^Ca/ || /^Switch/ || /^Rt/ { 94 nnodes++ 95 ntype=$1; nodeguid=substr($3, 4, 16); ports=$2 96 if ('$v') 97 print "\n# Checking " ntype ": nodeguid 0x" nodeguid 98 99 err = 0; 100 if (ntype != "Switch") 101 next 102 103 lid = substr($0, index($0, "port 0 lid ") + 11) 104 lid = substr(lid, 1, index(lid, " ") - 1) 105 err = check_node(lid, 255) 106 } 107/^\[/ { 108 nports++ 109 port = $1 110 sub("\\(.*\\)", "", port) 111 gsub("[\\[\\]]", "", port) 112 if (ntype != "Switch") { 113 lid = substr($0, index($0, " lid ") + 5) 114 lid = substr(lid, 1, index(lid, " ") - 1) 115 if (check_node(lid, port) == 2) 116 pcnterr++; 117 } else if (err && 118 system("'$IBPATH'/ibcheckerrs '"$ca_info"' '$gflags' '$verbose' '$brief' " lid " " port)) 119 pcnterr++; 120} 121 122/^ib/ {print $0; next} 123/ibpanic:/ {print $0} 124/ibwarn:/ {print $0} 125/iberror:/ {print $0} 126 127END { 128 printf "\n## Summary: %d nodes checked, %d bad nodes found\n", nnodes, ne 129 printf "## %d ports checked, %d ports have errors beyond threshold\n", nports, pcnterr 130 exit (ne + pcnterr) 131} 132' 133exit $rv 134