#!/bin/ksh # # check_lan_speed.ksh # # Olivier Masse, 2004/06/21 # # This script checks all lan interfaces on an HP-UX system and reports # their speed. # # # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # returncode=0 lanscan | grep ETHER | while read crap crap ppa state lan crap do speed=$(lanadmin -s $ppa) speedmbit=$(($speed / 1000000)) ifconfig $lan >/dev/null 2>&1 if [ $? -eq 0 ] then ifconfig $lan | tail -1 | read crap addr crap else addr="(unused)" fi if [ "$1" = "-v" ] then printf "================================================================\n" printf "%-10s %-10s %-10s %-20s\n" "Device" "State" "Speed" "Address" printf "%-10s %-10s %-10s %-20s\n" "--------" "--------" "--------" "----------------" printf "%-10s %-10s %-10s %-20s\n" /dev/$lan $state $speedmbit $addr printf "\n" printf "Specific device information:\n" printf "----------------------------\n" lanadmin -x $ppa fi if [ "$1" = "-halfduplex" -o "$1" = "" ] then if [ ! "$addr" = "(unused)" ] then lanadmin -x $ppa | grep -i "Half" | grep -q -i "Duplex" if [ "$?" -eq 0 ] then echo "check_lan_speed.ksh: I think that /dev/$lan ($addr) is at $speedmbit mbit HALF-DUPLEX." returncode=1 fi fi fi if [ "$1" = "-fullduplex" -o "$1" = "" ] then if [ ! "$addr" = "(unused)" ] then lanadmin -x $ppa | grep -i "Full" | grep -q -i "Duplex" if [ "$?" -eq 0 ] then echo "check_lan_speed.ksh: I think that /dev/$lan ($addr) is at $speedmbit mbit FULL-DUPLEX." returncode=1 fi fi fi if [ "$1" -a ! "$1" = "-fullduplex" -a ! "$1" = "-halfduplex" -a ! "$1" = "-v" ] then echo "Usage: $(basename $0) [-v|-halfduplex|-fullduplex]" exit 2 fi done exit $returncode