sexta-feira, 13 de fevereiro de 2009

Script para verificação de configuração da placa de rede ( Modelo Sun Fire )

Importante: Esse script somente funciona em servidores solaris e máquinas Sun Fire, qualquer versão !
PS: Irei também postar para as máquina Txxxx no próximo tópico !

Segue o script:

#!/bin/sh



# $Id: speed_duplex,v 1.3 2007/02/20 20:35:57 hutch Exp $



PATH=/bin:/usr/bin:/usr/sbin



# Print column header information

echo "Interface\tSpeed\t\tDuplex"

echo "---------\t-----\t\t------"



# Determine the speed and duplex for each live NIC on the system

for INTERFACE in `netstat -i | egrep -v "^Name|^lo0" \

| awk '{print $1}' | cut -d: -f1 | sort | uniq`

do

# Only gather information for active interfaces

# Note: "ce" interfaces can be "UP" in "ifconfig" but have link down

ifconfig $INTERFACE | grep "^$INTERFACE:.* /dev/null 2>&1 || continue

# Skip "cip" ATM interfaces

echo $INTERFACE | grep "^cip" > /dev/null 2>&1 && continue

# "ce" interfaces

if [ "`echo $INTERFACE | awk '/^ce[0-9]+/ { print }'`" ] ; then

kstat > /dev/null 2>&1

if [ $? -ne 0 ] ; then

echo "The \"kstat\" command failed for interface $INTERFACE."

continue

fi

# Determine the ce interface number

INSTANCE=`echo $INTERFACE | cut -c 3-`

DUPLEX=`kstat ce:$INSTANCE | grep link_duplex | awk '{ print $2 }'`

case "$DUPLEX" in

0) DUPLEX="link down" ;;

1) DUPLEX="half" ;;

2) DUPLEX="full" ;;

esac

SPEED=`kstat ce:$INSTANCE | grep link_speed | awk '{ print $2 }'`

case "$SPEED" in

0) SPEED="link down" ;;

10) SPEED="10 Mbit/s" ;;

100) SPEED="100 Mbit/s" ;;

1000) SPEED="1 Gbit/s" ;;

esac

# "dmfe" interfaces

elif [ "`echo $INTERFACE | awk '/^dmfe[0-9]+/ { print }'`" ] ; then

# Only the root user should run "ndd"

if [ "`id | cut -c1-5`" != "uid=0" ] ; then

echo "You must be the root user to determine \

${INTERFACE_TYPE}${INSTANCE} speed and duplex information."

continue

fi

DUPLEX=`ndd /dev/${INTERFACE} link_mode`

case "$DUPLEX" in

0) DUPLEX="half" ;;

1) DUPLEX="full" ;;

esac

SPEED=`ndd /dev/${INTERFACE} link_speed`

case "$SPEED" in

10) SPEED="10 Mbit/s" ;;

100) SPEED="100 Mbit/s" ;;

1000) SPEED="1 Gbit/s" ;;

esac

# "bge" and "iprb" interfaces

elif [ "`echo $INTERFACE | awk '/^iprb[0-9]+|bge[0-9]+/ { print }'`" ] ; then

kstat > /dev/null 2>&1

if [ $? -ne 0 ] ; then

DUPLEX="The \"kstat\" command failed for interface $INTERFACE."

continue

fi

# Determine the bge|iprb interface number

INSTANCE=`echo $INTERFACE | tr -d '[a-z]'`

INTERFACE=`echo $INTERFACE | tr -d '[0-9]'`

DUPLEX=`kstat $INTERFACE:$INSTANCE | grep duplex | awk '{ print $2 }'`

SPEED=`kstat $INTERFACE:$INSTANCE | grep ifspeed | awk '{ print $2 }'`

case "$SPEED" in

10000000) SPEED="10 Mbit/s" ;;

100000000) SPEED="100 Mbit/s" ;;

1000000000) SPEED="1 Gbit/s" ;;

esac

# le interfaces are always 10 Mbit half-duplex

elif [ "`echo $INTERFACE | awk '/^le[0-9]+/ { print }'`" ] ; then

DUPLEX="half"

SPEED="10 Mbit/s"

# All other interfaces

else

INTERFACE_TYPE=`echo $INTERFACE | sed -e "s/[0-9]*$//"`

INSTANCE=`echo $INTERFACE | sed -e "s/^[a-z]*//"`

# Only the root user should run "ndd"

if [ "`id | cut -c1-5`" != "uid=0" ] ; then

echo "You must be the root user to determine \

${INTERFACE_TYPE}${INSTANCE} speed and duplex information."

continue

fi

ndd -set /dev/$INTERFACE_TYPE instance $INSTANCE

SPEED=`ndd -get /dev/$INTERFACE_TYPE link_speed`

case "$SPEED" in

0) SPEED="10 Mbit/s" ;;

1) SPEED="100 Mbit/s" ;;

1000) SPEED="1 Gbit/s" ;;

esac

DUPLEX=`ndd -get /dev/$INTERFACE_TYPE link_mode`

case "$DUPLEX" in

0) DUPLEX="half" ;;

1) DUPLEX="full" ;;

*) DUPLEX="" ;;

esac

fi

echo "$INTERFACE\t\t$SPEED\t$DUPLEX"

done




PS: Abaixo o resultado da execução do script:

Interface Speed Duplex
--------- ----- ------
ce0 100 Mbit/s full

Nenhum comentário: