#!/bin/ksh # #*********************************************************************************** #* Scipt: checknic * #*********************************************************************************** #* Description: This program queries the system to determine the state of the * #* network interface on a Tru64 system. * #* To test the status of the network link, the local gateway is * #* pinged 3 times. * #*********************************************************************************** #* Parameters: checknic [[NIC] [-s|-d|-c]] * #* NIC = the network interface eg tu0 or ee0 * #* -s = display short (1 line) output * #* -d = display detailed output * #* -c = change port speed of the NIC interface * #*********************************************************************************** #* Revision: v1.40 * #*********************************************************************************** #* Rev History: * #* 13 Jun 2002 - release 1.4 * #* 13 Jun 2002 - Tested ok on v4.0F and v5.1A * #* 12 Jun 2002 - added extra parameter processing * #* 12 Jun 2002 - added checking for local gateway router by ping * #* 02 Jun 2002 - added code to modify port speed * #* 16 May 2002 - added front end to program * #* 24 Apr 2002 - modified code to procedural methodology * #* 15 Mar 2002 - created v1.0 to check the port speed * #*********************************************************************************** #* Future Devs: 1. Verify the ping is being sent through the interface chosen * #* 2. fix up change port speed logic and questions * #*********************************************************************************** ######################################################################### # Get The NIC value specified in the parameter list ######################################################################### PARAM=$1 typeset -i PARAMCOUNT=$# typeset -i RC OPTION="" NIC="" FOUND=N NICNetwork="" NetRAIN="" NICNetRAIN="" HOSTNAMEIP="" NICMACAddress="" NICIPAddress_pt1="" NICIPAddress_pt2="" NICIPAddress_pt3="" NICIPAddress_pt4="" LOCALGATEWAYROUTER="" VERSION="CheckNIC v1.4" case $PARAMCOUNT in 1) NIC=$1 OPTION=-d ;; 2) NIC=$1 OPTION=$2 ;; esac #Get Tru64 Version - USED FOR O/S SPECIFIC SETTINGS TRU64_VERSION=`uname -r` ######################################################################### # Get the NIC Name ######################################################################### GetNIC () { INTERFACE_LIST="`ifconfig -a | awk -F: '{print $1}' | grep -v inet | grep -v NetRAIN`" if [[ $PARAMCOUNT -eq 0 ]] then NIC=Unknown case $PARAM in $NIC) dummy=0;; *) echo $VERSION echo "Format: checknic [[NIC] [-s|-d|-c]]" echo "Option: -s=short display, -d=detailed display, -c=change port speed" echo "Please specify one of the following ports: { "$INTERFACE_LIST" }" exit ;; esac else for INTERFACE in $INTERFACE_LIST do if [ $INTERFACE = $PARAM ] then NIC=$PARAM FOUND=Y else if [ $FOUND = N ] then NIC=Unknown fi fi done fi case $PARAM in $NIC) dummy=0;; *) echo $VERSION echo "Format: checknic [[NIC] [-s|-d|-c]]" echo "Option: -s=short display, -d=detailed display, -c=change port speed" echo "Please specify one of the following ports: { "$INTERFACE_LIST" }" exit ;; esac } ######################################################################### # Get Server HostName ######################################################################### GetMachineName () { HOSTNAME=`uname -n` if [[ $HOSTNAME = "sapqas" ]] then HOSTNAME=`cat /.profile | grep PS1| awk -F'="' '{print $2}'| awk '{print $1}'` fi HOSTNAMEIP=`cat /etc/hosts | grep $HOSTNAME | head -1 | awk '{print $1}'` } ######################################################################### # Get Port Speed Of the NIC ######################################################################### GetNICPortSpeed () { case $TRU64_VERSION in V4.0) case $NIC in "tu0") PortSpeed=`cat /var/adm/messages|grep "$NIC"|grep duplex| tail -1| awk -F'tu0:' '{print $2}'|awk -Fselecting '{print $2}'| tr '[A-Z]' '[a-z]'| cut -c2-40` ;; "tu1") PortSpeed=`cat /var/adm/messages|grep "$NIC"|grep duplex| tail -1| awk -F'tu1:' '{print $2}'|awk -Fselecting '{print $2}'| tr '[A-Z]' '[a-z]'| cut -c2-40` ;; "tu2") PortSpeed=`cat /var/adm/messages|grep "$NIC"|grep duplex| tail -1| awk -F'tu2:' '{print $2}'|awk -Fselecting '{print $2}'| tr '[A-Z]' '[a-z]'| cut -c2-40` ;; "ee0") PortSpeed=`cat /var/adm/messages|grep "$NIC"|grep duplex| tail -1| awk -F'ee0:' '{print $2}'| tr '[A-Z]' '[a-z]'| cut -c2-40` ;; "ee1") PortSpeed=`cat /var/adm/messages|grep "$NIC"|grep duplex| tail -1| awk -F'ee1:' '{print $2}'| tr '[A-Z]' '[a-z]'| cut -c2-40` ;; "ee2") PortSpeed=`cat /var/adm/messages|grep "$NIC"|grep duplex| tail -1| awk -F'ee2:' '{print $2}'| tr '[A-Z]' '[a-z]'| cut -c2-40` ;; esac ;; V5.1) PortInfo=`hwmgr -show comp | grep $NIC |awk -F: '{print $1}'` PortAccessSpeed=`hwmgr -g att -id $PortInfo | grep 'media_speed ' | awk '{print $3}'`"MHz" PortDuplexCheck=`hwmgr -g att -id $PortInfo | grep 'full_duplex = 1'` ; RC=$? if [[ $RC -eq 0 ]] then PortNegotiation=FullDuplex else PortNegotiation=HalfDuplex fi PortMTU="MTU:"`hwmgr -g att -id $PortInfo | grep 'MTU_size ' | awk '{print $3}' ` PortAccessState=`hwmgr -g att -id $PortInfo | grep 'access_state ' | awk '{print $3}'` PortSpeed="$PortAccessSpeed ($PortNegotiation) , $PortMTU , $PortAccessState" ;; esac } ######################################################################### # Get Extra NIC Information ######################################################################### GetNICMACAddress () { NICMACAddress=`cat /var/adm/messages| grep $NIC | grep -i hardware |sort -u | tail -1 | awk -Faddress: '{print $2}' | awk '{print $1}'` #NICMACAddress=`netstat -I tu0 | grep '' | awk '{print $4}'` if [ $NICMACAddress = "" ] then NICMACAddress=Unknown fi NetRAIN="N" ifconfig $NIC | grep NetRAIN 2>&1 >/dev/null ; RC=$? if [ $RC = 0 ] then NetRAIN="Y" NICIPAddress_pt3=`ifconfig $NIC | grep NetRAIN | grep Virtual | sed 's/^[ ]*//'` NICIPAddress_pt4=`ifconfig $NIC | grep NetRAIN | grep Attached | sed 's/^[ ]*//'` NICNetRAIN=`ifconfig $NIC | grep NetRAIN | grep Virtual | awk '{print $4}'` NICIPAddress_pt1=`ifconfig $NICNetRAIN | grep inet | sed 's/^[ ]*//' | awk -Fbroadcast '{print $1}'` NICIPAddress_pt2=`ifconfig $NICNetRAIN | grep inet | sed 's/^[ ]*//' | awk -Fbroadcast '{print "broadcast"$2}'` else NetRAIN="N" NICIPAddress_pt1=`ifconfig $NIC | grep inet | sed 's/^[ ]*//' | awk -Fbroadcast '{print $1}'` NICIPAddress_pt2=`ifconfig $NIC | grep inet | sed 's/^[ ]*//' | awk -Fbroadcast '{print "broadcast"$2}'` NICIPAddress_pt3="N/A" NICIPAddress_pt4="N/A" fi } ######################################################################### # Ping ANOTHER NETWORK NODE TO TEST THE NETWORK IS UP ######################################################################### TestNICNetworkUP () { #IPADDRESS_1="" #IPADDRESS_2="" LOCALGATEWAYROUTER=`cat /etc/routes | grep default | awk -Fdefault '{print $2}'|awk '{print $1}'` IPADDRESS_1=`echo "$LOCALGATEWAYROUTER" | grep '.'` IPADDRESS_2="`cat /etc/hosts | grep $LOCALGATEWAYROUTER | awk '{print $1}'`" PINGCOUNT=3 ping -q -c $PINGCOUNT -I $NIC $LOCALGATEWAYROUTER 2>&1 1>/dev/null ; RC=$? if [ $RC = 0 ] then if [[ $IPADDRESS_1 = "" ]] then NICNetwork="Link UP to Local Gateway $LOCALGATEWAYROUTER" else if [[ $IPADDRESS_2 = "" ]] then NICNetwork="Link UP to Local Gateway $LOCALGATEWAYROUTER (NoName)" else NICNetwork="Link UP to Local Gateway $LOCALGATEWAYROUTER ($IPADDRESS_2)" fi fi else if [[ $IPADDRESS_1 = "" ]] then NICNetwork="Link DOWN to Local Gateway $LOCALGATEWAYROUTER" else if [[ $IPADDRESS_2 = "" ]] then NICNetwork="Link DOWN to Local Gateway $LOCALGATEWAYROUTER (NoName)" else NICNetwork="Link DOWN to Local Gateway $LOCALGATEWAYROUTER ($IPADDRESS_2)" fi fi fi } ######################################################################### # Change the NIC speed to 100Mbps FULL DUPLEX ######################################################################### DisplayNICStatus () { case $OPTION in -s) if [ $NetRAIN = "Y" ] then echo "$HOSTNAME: $NICNetRAIN ($NIC ($NICMACAddress)) , $NICNetwork , $PortSpeed" else echo "$HOSTNAME: $NIC ($NICMACAddress) , $NICNetwork , $PortSpeed" fi ;; -d) echo "------------------------------------------------------------------" echo "$VERSION" echo "------------------------------------------------------------------" echo "SERVER Name: $HOSTNAME" echo "SERVER IP : $HOSTNAMEIP" if [ $NetRAIN = "Y" ] then echo "NetRAIN IF : $NICIPAddress_pt3" echo " : $NICIPAddress_pt4" echo "NetRAIN IP : $NICIPAddress_pt1" echo " : $NICIPAddress_pt2" else echo "NIC IP : $NICIPAddress_pt1" echo " : $NICIPAddress_pt2" fi echo "NIC Name : $NIC" echo "MAC Address: $NICMACAddress" echo "PORT Speed : $PortSpeed" echo "NET Status : $NICNetwork" echo "------------------------------------------------------------------" ;; esac } ######################################################################### # Change the NIC speed to 100Mbps FULL DUPLEX ######################################################################### ChangeNICSpeed () { case $OPTION in -c) #if [[ ! $PortSpeed = '100 mbps full duplex' && ! $PortSpeed = '100basetx (utp) port: full duplex' ]] #if [[ ! $PortSpeed = '100 mbps full duplex' && ! $PortSpeed = '100basetx (utp) port: full duplex' ]] #then echo "SERVER: $HOSTNAME NIC: $NIC OLD Speed: $PortSpeed" echo "Do you wish to change the port speed (Y/N): \c" read ANSWER case $ANSWER in Y|y) echo " _____________________________________" echo " Port Speed / Value Configuration" echo " _____________________________________" echo " 10 10 Mbps Ethernet half-duplex" echo " 20 10 Mbps Ethernet full-duplex" echo " 100 100 Mbps Ethernet half-duplex" echo " 200 100 Mbps Ethernet full-duplex" echo " _____________________________________" echo "\nSelect Speed: \c"; read NICPortSpeed ifconfig $NIC down ifconfig $NIC speed $NICPortSpeed up sleep 2 echo "111" GetNICPortSpeed echo "222" GetNICMACAddress echo "333" GetNICPortSpeed echo "444" TestNICNetworkUP echo "555" DisplayNICStatus ;; N|n) echo "Not changing port speed" ;; esac #fi ;; esac } ######################################################################### # MAIN PROGRAM ######################################################################### GetNIC GetMachineName case $NIC in tu?|ee?) GetNICMACAddress GetNICPortSpeed TestNICNetworkUP DisplayNICStatus ChangeNICSpeed ;; esac