PageRenderTime 45ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/network.ksh

http://github.com/geekcomputers/Shell
Korn Shell | 306 lines | 188 code | 38 blank | 80 comment | 5 complexity | e23b09c0a944701fdd3a826c19b09789 MD5 | raw file
  1. #!/bin/ksh
  2. #set -x
  3. ################################################################################
  4. # Simple script to GET stats about network cards
  5. # Should work on hme and qfe. Will NOT change anything.
  6. # Will report on speed and config of all network interfaces.
  7. # Paul Bates 27.03.2000
  8. # James Council 26.09.2001
  9. # - Changed output to one liners.
  10. # - Added IPversion check.
  11. # James Council 10.10.2002 (jamescouncil@yahoo.com)
  12. # - Added test for Cassini Gigabit-Ethernet card (ce_).
  13. # - Added test for GEM Gigabit-Ethernet (ge_)
  14. # - Added test for eri Fast-Ethernet (eri_).
  15. # - Added "Ethernet Address" field.
  16. # - Removed "IPversion" field.
  17. # - Removed checking of a port more than once (i.e. qfe0 qfe0:1)
  18. # James Council 10.25.2002 (jamescouncil@yahoo.com)
  19. # - Fixed 1GB check on ge device.
  20. # James Council 04.02.2003 (jamescouncil@yahoo.com)
  21. # - Added dmfe check (suggested by John W. Rudick, & Erlend Tronsmoen)
  22. # Octave Orgeron 02.06.2004 (unixconsole@yahoo.com)
  23. # - Added bge check (bge_).
  24. # Octave Orgeron 05.18.2005 (unixconsole@yahoo.com)
  25. # - Corrected CE check to use kstat, which is required in Solaris 10.
  26. # Paul Bates 21.11.2005 (sun@paulbates.org)
  27. # - Corrected Cassini GE check to use cap_autoneg not adv_cap_autoneg
  28. # - Thanks to Christian Jose of CSC for finding bug and suggesting fix.
  29. # Octave Orgeron 12.13:2005 (unixconsole@yahoo.com)
  30. # - Corrected DMFE check. Added IPGE check. Special thanks to
  31. # Paul Bates, Christian Jose, and Bill Qualye for suggesting fixes and
  32. # for keeping me on my toes;)
  33. # NOTE: For further updates or comments please feel free to contact me via
  34. # email. James Council or Octave Orgeron
  35. #
  36. ################################################################################
  37. NDD=/usr/sbin/ndd
  38. KSTAT=/usr/bin/kstat
  39. IFC=/sbin/ifconfig
  40. typeset -R5 LINK
  41. typeset -R9 AUTOSPEED
  42. typeset -R6 STATUS
  43. typeset -R6 SPEED
  44. typeset -R5 MODE
  45. typeset -R18 ETHER
  46. #---- Function to test that the user is root.
  47. #
  48. Check_ID()
  49. {
  50. ID=$(/usr/ucb/whoami)
  51. if [ $ID != "root" ]; then
  52. echo "$ID, you must be root to run this program."
  53. exit 1
  54. fi
  55. }
  56. #---- Function to test a Intel 82571-based ethernet controller port (i.e. ipge_).
  57. #
  58. Check_IPGE()
  59. {
  60. autospeed=`${KSTAT} -m ipge -i $num -s cap_autoneg | grep cap_autoneg | awk '{print $2}'`
  61. case $autospeed in
  62. 1) AUTOSPEED=on ;;
  63. 0) AUTOSPEED=off ;;
  64. *) AUTOSPEED=Error ;;
  65. esac
  66. status=`${KSTAT} -m ipge -i $num -s link_up | grep link_up | awk '{print $2}'`
  67. case $status in
  68. 1) STATUS=Up ;;
  69. 0) STATUS=DOWN ;;
  70. *) STATUS=Error ;;
  71. esac
  72. speed=`${KSTAT} -m ipge -i $num -s link_speed | grep link_speed | awk '{print $2}'`
  73. case $speed in
  74. 1000) SPEED=1GB ;;
  75. 100) SPEED=100MB ;;
  76. 10) SPEED=10MB ;;
  77. 0) SPEED=10MB ;;
  78. *) SPEED=Error ;;
  79. esac
  80. mode=`${KSTAT} -m ipge -i $num -s link_duplex | grep link_duplex | awk '{print $2}'`
  81. case $mode in
  82. 2) MODE=FDX ;;
  83. 1) MODE=HDX ;;
  84. 0) MODE=--- ;;
  85. *) MODE=Error ;;
  86. esac
  87. }
  88. #---- Function to test a Cassini Gigabit-Ethernet port (i.e. ce_).
  89. #
  90. Check_CE()
  91. {
  92. autospeed=`${KSTAT} -m ce -i $num -s cap_autoneg | grep cap_autoneg | awk '{print $2}'`
  93. case $autospeed in
  94. 1) AUTOSPEED=on ;;
  95. 0) AUTOSPEED=off ;;
  96. *) AUTOSPEED=Error ;;
  97. esac
  98. status=`${KSTAT} -m ce -i $num -s link_up | grep link_up | awk '{print $2}'`
  99. case $status in
  100. 1) STATUS=Up ;;
  101. 0) STATUS=DOWN ;;
  102. *) STATUS=Error ;;
  103. esac
  104. speed=`${KSTAT} -m ce -i $num -s link_speed | grep link_speed | awk '{print $2}'`
  105. case $speed in
  106. 1000) SPEED=1GB ;;
  107. 100) SPEED=100MB ;;
  108. 10) SPEED=10MB ;;
  109. 0) SPEED=10MB ;;
  110. *) SPEED=Error ;;
  111. esac
  112. mode=`${KSTAT} -m ce -i $num -s link_duplex | grep link_duplex | awk '{print $2}'`
  113. case $mode in
  114. 2) MODE=FDX ;;
  115. 1) MODE=HDX ;;
  116. 0) MODE=--- ;;
  117. *) MODE=Error ;;
  118. esac
  119. }
  120. #---- Function to test Quad Fast-Ethernet, Fast-Ethernet, and
  121. # GEM Gigabit-Ethernet (i.e. qfe_, hme_, ge_)
  122. #
  123. Check_NIC()
  124. {
  125. ${NDD} -set /dev/${1} instance ${2}
  126. if [ $type = "ge" ];then
  127. autospeed=`${NDD} -get /dev/${1} adv_1000autoneg_cap`
  128. else autospeed=`${NDD} -get /dev/${1} adv_autoneg_cap`
  129. fi
  130. case $autospeed in
  131. 1) AUTOSPEED=on ;;
  132. 0) AUTOSPEED=off ;;
  133. *) AUTOSPEED=Error ;;
  134. esac
  135. status=`${NDD} -get /dev/${1} link_status`
  136. case $status in
  137. 1) STATUS=Up ;;
  138. 0) STATUS=DOWN ;;
  139. *) STATUS=Error ;;
  140. esac
  141. speed=`${NDD} -get /dev/${1} link_speed`
  142. case $speed in
  143. 1000) SPEED=1GB ;;
  144. 1) SPEED=100MB ;;
  145. 0) SPEED=10MB ;;
  146. *) SPEED=Error ;;
  147. esac
  148. mode=`${NDD} -get /dev/${1} link_mode`
  149. case $mode in
  150. 1) MODE=FDX ;;
  151. 0) MODE=HDX ;;
  152. *) MODE=Error ;;
  153. esac
  154. }
  155. #---- Function to test the Davicom Fast Ethernet, DM9102A, devices
  156. # on the Netra X1 and SunFire V100 (i.e. dmfe_)
  157. #
  158. Check_DMF_NIC()
  159. {
  160. autospeed=`${NDD} -get /dev/${1}${2} adv_autoneg_cap`
  161. case $autospeed in
  162. 1) AUTOSPEED=on ;;
  163. 0) AUTOSPEED=off ;;
  164. *) AUTOSPEED=Error ;;
  165. esac
  166. status=`${NDD} -get /dev/${1}${2} link_status`
  167. case $status in
  168. 1) STATUS=Up ;;
  169. 0) STATUS=DOWN ;;
  170. *) STATUS=Error ;;
  171. esac
  172. speed=`${NDD} -get /dev/${1}${2} link_speed`
  173. case $speed in
  174. 100) SPEED=100MB ;;
  175. 10) SPEED=10MB ;;
  176. 0) SPEED=10MB ;;
  177. *) SPEED=Error ;;
  178. esac
  179. mode=`${NDD} -get /dev/${1}${2} link_mode`
  180. case $mode in
  181. 2) MODE=FDX ;;
  182. 1) MODE=HDX ;;
  183. 0) MODE=--- ;;
  184. *) MODE=Error ;;
  185. esac
  186. }
  187. # Function to detect Sun BGE interface on Sun Fire V210 and V240.
  188. # The BGE is a Broadcom BCM5704 chipset. There are four interfaces
  189. # on the V210 and V240.
  190. Check_BGE_NIC()
  191. {
  192. autospeed=`${NDD} -get /dev/${1}${2} adv_autoneg_cap`
  193. case $autospeed in
  194. 1) AUTOSPEED=on ;;
  195. 0) AUTOSPEED=off ;;
  196. *) AUTOSPEED=Error ;;
  197. esac
  198. status=`${NDD} -get /dev/${1}${2} link_status`
  199. case $status in
  200. 1) STATUS=Up ;;
  201. 0) STATUS=DOWN ;;
  202. *) STATUS=Error ;;
  203. esac
  204. speed=`${NDD} -get /dev/${1}${2} link_speed`
  205. case $speed in
  206. 1000) SPEED=1GB ;;
  207. 100) SPEED=100MB ;;
  208. 10) SPEED=10MB ;;
  209. 0) SPEED=10MB ;;
  210. *) SPEED=Error ;;
  211. esac
  212. mode=`${NDD} -get /dev/${1}${2} link_duplex`
  213. case $mode in
  214. 2) MODE=FDX ;;
  215. 1) MODE=HDX ;;
  216. 0) MODE=--- ;;
  217. *) MODE=Error ;;
  218. esac
  219. }
  220. #############################################
  221. # Start
  222. #############################################
  223. #
  224. Check_ID
  225. # Output header.
  226. echo
  227. echo " Link Autospeed Status Speed Mode Ethernet Address"
  228. echo "----- --------- ------ ------ ----- ------------------"
  229. # Create a uniq list of network ports configured on the system.
  230. #
  231. # NOTE: This is done to avoid multiple references to a single network port
  232. # (i.e. qfe0 and qfe0:1).
  233. #
  234. for LINK in `${IFC} -a| egrep -v "lo|be|dman|lpfc"| \
  235. awk -F: '/^[a-z,A-z]/ {print $1}'| sort -u`
  236. do
  237. type=$(echo $LINK | sed 's/[0-9]//g')
  238. num=$(echo $LINK | sed 's/[a-z,A-Z]//g')
  239. # Here we reference the functions above to set the variables for each port which
  240. # will be outputed below.
  241. #
  242. case $type in
  243. bge) Check_BGE_NIC $type $num ;;
  244. ce) Check_CE $type $num ;;
  245. dmfe) Check_DMF_NIC $type $num ;;
  246. ipge) Check_IPGE $type $num ;;
  247. *) Check_NIC $type $num ;;
  248. esac
  249. # Set ethernet variable and output all findings for a port to the screen.
  250. #
  251. ETHER=`${IFC} ${LINK}| awk '/ether/ {print $2}'`
  252. echo "$LINK $AUTOSPEED $STATUS $SPEED $MODE $ETHER"
  253. done
  254. set +x
  255. #############################################
  256. # End
  257. #############################################
  258. ##############################################################################
  259. ### This script is submitted to BigAdmin by a user of the BigAdmin community.
  260. ### Sun Microsystems, Inc. is not responsible for the
  261. ### contents or the code enclosed.
  262. ###
  263. ###
  264. ### Copyright 2006 Sun Microsystems, Inc. ALL RIGHTS RESERVED
  265. ### Use of this software is authorized pursuant to the
  266. ### terms of the license found at
  267. ### http://www.sun.com/bigadmin/common/berkeley_license.html
  268. ##############################################################################