Por cierto un saludo a aquellos Sysadmin que son lectores o bien
usuarios que les interesan estos articulos, y les doy la bienvenida a
este 2007 prometiendo colaborar aun más con todos.
#!/bin/sh
###
# Script que verifica las interfaces de red
#
###
# Necesitas privilegios de root para lograr una salida.
root_check ()
{
if [ "`/usr/bin/id | /usr/bin/cut -c1-5`" != "uid=0" ] ; then
echo "Interface $INTERFACE requires root user priveledges."
ROOT=1
fi
}
# speed lookup
speed_lookup ()
{
case $1 in
0) SPEED="10 Mbit/s" ;;
1) SPEED="100 Mbit/s" ;;
10) SPEED="10 Mbit/s" ;;
100) SPEED="100 Mbit/s" ;;
1000) SPEED="1 Gbit/s" ;;
10000000) SPEED="10 Mbit/s" ;;
100000000) SPEED="100 Mbit/s" ;;
1000000000) SPEED="1 Gbit/s" ;;
esac
}
duplex_lookup ()
{
case $1 in
0) DUPLEX="link down" ;;
1) DUPLEX="half" ;;
2) DUPLEX="full" ;;
half) DUPLEX="half" ;;
full) DUPLEX="full" ;;
ndd_0) DUPLEX="half" ;;
ndd_1) DUPLEX="full" ;;
esac
}
# ndd routine
ndd_set ()
{
RESULT=`ndd -set /dev/$DEVICE $1`
}
ndd_get ()
{
VALUE=`ndd -get /dev/$DEVICE $1`
}
# kstat routine
kstat_get ()
{
set - `kstat -p "$DEVICE:$INSTANCE:$INTERFACE:$1"`
VALUE=$2
}
# Interface Routines
ce_get ()
{
kstat_get "link_speed"
speed_lookup $VALUE
kstat_get "link_duplex"
duplex_lookup $VALUE
}
qfe_get ()
{
kstat_get "ifspeed"
speed_lookup $VALUE
if [ `uname -r` = "5.8" ]; then
root_check
if [ ! $ROOT ]; then
ndd_set "instance $INSTANCE"
ndd_get "link_mode"
duplex_lookup "ndd_$VALUE"
fi
else
kstat_get "link_duplex"
duplex_lookup $VALUE
fi
}
nge_get ()
{
kstat_get "ifspeed"
speed_lookup $VALUE
kstat_get "duplex"
duplex_lookup $VALUE
}
ge_get ()
{
root_check
if [ ! $ROOT ]; then
ndd_set "instance $INSTANCE"
ndd_get "link_speed"
speed_lookup $VALUE
ndd_get "link_mode"
duplex_lookup "ndd_$VALUE"
fi
}
dman_get ()
{
SPEED=internal
DUPLEX=n/a
}
interface ()
{
INTERFACE=$1
set - `echo "$1" | sed -e 's/[0-9]\{1,\}/ &/g;'`
DEVICE=$1
INSTANCE=$2
case $DEVICE in
ce) ce_get;;
nge|bge) nge_get;;
dman) dman_get;;
ge) ge_get;;
qfe|hme|eri) qfe_get;;
*) echo "Unknown interface $INTERFACE";;
esac
}
# Imprime la cabecera
/usr/bin/echo "Interface\tSpeed\t\tDuplex"
/usr/bin/echo "---------\t-----\t\t------"
# Determina la velocidad
for INTERFACE in `/usr/bin/netstat -i | /usr/bin/egrep -v "^Name|^lo0"
\
| /usr/bin/awk '{print $1}' | /usr/bin/sort | /usr/bin/uniq`
do
unset SPEED; unset DUPLEX; unset DEVICE; unset INSTANCE
interface $INTERFACE
/usr/bin/echo "$INTERFACE\t\t$SPEED\t$DUPLEX"
done