#!/bin/ksh # # @(#)ethchk 1.2 20030112 halvard halvorsen # PATH=/usr/bin:/usr/sbin thisone=`basename $0` pline="-----------------------------------------------------------------------------" # # check that we are root # '/usr/xpg4/bin/id -u ' is more elegant - can't trust it's there # so use good old /usr/bin/id with some awk # uid=`id | awk -F= '{print $2}' | awk -F"(" '{print $1}' 2>/dev/null` if [ $uid -eq 0 ] then : else print "$thisone: ERROR - you have to be root to run this script." print "" exit 1 fi # # generate list of all interfaces # inflist=`ifconfig -a | grep ^[a-z] | egrep -v "lo|le" | awk -F: '{print $1}'| sort | uniq 2>/dev/null ` unsupported=`ifconfig -a | egrep ^le | nawk -F"[0-9]" '{print $1}' | sort | uniq 2>/dev/null` if [ ! -z "$unsupported" ] then print "$thisone: INFO - the $unsupported interface(s) are unsupported by this script" print "$thisone: INFO - ndd does not support interfaces of this type" fi if [ -z "$inflist" ] then print "$thisone: empty interface list" exit 2 fi # # cycle through them and print settings # for inf in $inflist do echo "$pline" # # not sure if this is crude or elegant - but nawk is a godsend # assume all interface types are 2 or 3 letters (e.g. "ge" or "eri"). # intfctype=`echo $inf | nawk -F"[0-9]" '{print $1}'` instance=`echo $inf | nawk -F"[a-z][a-z]|[a-z][a-z][a-z]" '{print $2}'` print " status for interface ${intfctype}$instance" # # interface to check # ndd -set /dev/$intfctype instance $instance # # some interfaces does not produce link status etc # /usr/sbin/ndd /dev/$intfctype \? | egrep -s link_status 2>/dev/null ls=$? if [ $ls -eq 0 ] then if [ $(/usr/sbin/ndd -get /dev/$intfctype link_status) -eq 1 ] then print -n " $intfctype$instance link is up" else print -n " $intfctype$instance link is down" fi fi # # speed check # case "$intfctype" in hme|qfe|eri) if [ $(/usr/sbin/ndd -get /dev/$intfctype link_speed) -eq 1 ] then print -n ", speed is 100 Mbit/sec" else print -n ", speed is 10 Mbit/sec" fi ;; ge) if [ $(/usr/sbin/ndd -get /dev/$intfctype link_speed) -eq 1000 ] then print -n ", speed is 1000 Mbit/sec" else print -n ", link is not up" fi ;; esac /usr/sbin/ndd /dev/$intfctype \? | egrep -s link_mode 2>/dev/null lm=$? if [ $lm -eq 0 ] then if [ $(/usr/sbin/ndd -get /dev/$intfctype link_mode) -eq 1 ] then print ",full duplex" else print ",half duplex" fi fi print "" count=0 for p in `/usr/sbin/ndd /dev/$intfctype \? | grep -v "?"| awk '{print $1}' 2>/dev/null` do count=`expr $count \+ 1` nddval=$(ndd -get /dev/$intfctype "$p") printf "%25s%1s" $p: printf "%3d" $nddval if [ $count -eq 2 ] then count=0 print "" fi done # make sure output comes out pretty when even number of parameters if [ $count -eq 1 ] then print "" fi done echo "$pline" exit 0