Duplex Script - output format issue.


 
Thread Tools Search this Thread
Operating Systems Solaris Duplex Script - output format issue.
# 1  
Old 03-30-2010
Duplex Script - output format issue.

Hi Gurus,
I had downloaded the below script from the net and used it to get the Link and duplex settings in my Sun servers.

In all except one(Sol-5.10 on X86) i am getting output format like below:

Code:
 
[!]root: /var/ADMIN/bin/speed_duplex.sh
Interface       Speed           Duplex
---------       -----           ------
e1000g0         1000000000
1000000000      full


In all other servers the output format looks good(as shown below):

[!]root: /var/ADMIN/bin/speed_duplex.sh
Interface Speed Duplex
--------- ----- ------
hme0 100 Mbit/s full



The script is appended herewith:

Code:
 
[!]root: cat /var/ADMIN/bin/speed_duplex.sh
#!/bin/sh
# $Id: speed_duplex,v 1.4 2007/07/10 16:04:42 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:.*<UP," > /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
   elif [ "`echo $INTERFACE | awk '/^e1000g[0-9]+/ { print }'`" ] ; then
      INSTANCE=`echo $INTERFACE | cut -c7-`
      # The duplex for e1000g devices can only be found with "dladm"
      DUPLEX=`dladm show-dev $INTERFACE | awk '{ print $NF }'`
      SPEED=`kstat e1000g:$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

Any idea where i need to make the modifications to make the output look good.

HG
# 2  
Old 03-30-2010
Replace line 78:
Code:
SPEED=`kstat e1000g:$INSTANCE | grep ifspeed | awk '{ print $2 }'`

by
Code:
SPEED=`kstat e1000g:$INSTANCE | grep ifspeed | head -1 | awk '{ print $2 }'`

# 3  
Old 03-31-2010
Thanks jlliagre....It worked.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to generate Excel file or to SQL output data to Excel format/tabular format

Hi , i am generating some data by firing sql query with connecting to the database by my solaris box. The below one should be the header line of my excel ,here its coming in separate row. TO_CHAR(C. CURR_EMP_NO ---------- --------------- LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies

2. Shell Programming and Scripting

awk Script to format output

Hi all, I'm fairly new to this and learning along the way, so bare with me... I'm trying to format the output from a script to be more read-friendly. The output contains more servers and more processes but for as example it will do: Server: Test1 ... (4 Replies)
Discussion started by: Bobsonm
4 Replies

3. Shell Programming and Scripting

Output not in correct format - cd script

I have a script that looks like this: dirname2=/usr/tmp/filelist/*/* for dirname2 in /tmp/filelist/*/*; do (cd $dirname2/catalog ||echo "file does not exist" && echo "$dirname2" |cut -d '/' -f 7,8 && echo $i && ls -la |awk 'NR>3 {SUM += $5} END { print "Total number of kb " SUM }');done... (2 Replies)
Discussion started by: newbie2010
2 Replies

4. Shell Programming and Scripting

Format output issue

Dear Friends, Need your help. $cat input.txt TITLE Date:01-01-2011 Day: Friday Details Particulares Qty $ $ $ $ $ $more test.sh cat input.txt | while read line do echo "${line}" done $ $ (5 Replies)
Discussion started by: anushree.a
5 Replies

5. Shell Programming and Scripting

"links -dump" output format issue

Hi All, I tried searching a lot about this but to no avail. I have a HTML file. I used links -dump file_page.html > text_html.txt What the above command gave me was a filtered text from the HTML file with tags removed. Now, the the output from the above command looked something like this:... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

6. Shell Programming and Scripting

shell script to format command output

Hello team, I am running below command which is giving following output. bash-3.00$ ps -eo pid,pcpu,args | sort +1n | grep -i java 12 0.0 grep -i java 8804 0.0 /opt/app/ccr/home/ccr/WebSphere/AppServer/java/bin/sparcv9/java -XX:+UnlockDiag 9241 0.0... (7 Replies)
Discussion started by: coolguyamy
7 Replies

7. Solaris

How to find half duplex or full duplex

Hi, How to find whether the server is running with half duplex or full duplex. I tried with the following command ndd -get /dev/ but am not getting any output,. Is the command correct? Also let me know how to change from half to full duplex. (1 Reply)
Discussion started by: rogerben
1 Replies

8. Shell Programming and Scripting

Script output format

Hi Gurus, 1. I have a script to run a SQL report. The script ran fine, but the format of the output is not satisfactory in that I see too much white space in between the lines in the output file (logfile). Please see the example below: 010192S.CD 01117CV000A.CD ... (6 Replies)
Discussion started by: syang68
6 Replies

9. Shell Programming and Scripting

Format output using awk in script.

Guys, I have a script which hits the database and pulls the information that I need into files. Now I want to format these files to make them easy to read. The sample format of the file will be like.... <Start_of_File> Header1 .....xsdfsfa...adfa...... Header2 ....afefas .aefaefsdf...... (8 Replies)
Discussion started by: bperl
8 Replies

10. UNIX for Dummies Questions & Answers

File Format issue: Output of sqlplus

Hi, I am using a query like below in my shell script : { { echo "set echo off" echo "set head off" echo "whenever sqlerror exit -1; select NUMBER ||','|| FNAME ||','|| LOC ||','|| ... (2 Replies)
Discussion started by: deepakgang
2 Replies
Login or Register to Ask a Question