Computing.Net > Forums > Unix > Help with a shell script

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Help with a shell script

Reply to Message Icon

Name: jrmontg
Date: July 11, 2006 at 08:15:23 Pacific
OS: UNIX
CPU/Ram: Intel Xeon
Product: HP
Comment:

I need a file to run a ndstat -l and find the line "Interface speed: 1000 Mbits/sec" and extract the 1000 Mbits/sec and add it to a file.

Thanks for the help

jrmontg



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: July 11, 2006 at 10:12:45 Pacific
Reply:


Typical output of the ndstat -l command looks like this (# comments are mine):

# start ndstat output
DLPI Module Info: 2 SAPs open, 16 SAPs maximum

96687 frames received destined for an unbound SAP

MAC Driver Info: Media_type: Ethernet
Min_SDU: 14, Max_SDU: 1514, Address length: 6
Interface speed: 1000 Mbits/sec
# End ndstat output

How about an awk script that searches for the first two fields equal "Interface" & "speed:" and print everything from field 3 to the end of the line:

#!/bin/ksh
# myscript.ss

ndstat -l|awk ' { if( $1 == "Interface" && $2 == "speed:")
for(i=3; i <= NF; i++)
printf("%s ", $i) } '

I don't know what "add it to a file" means, but executing:

myscript.ss >> new.file

appends the output of myscript.ss to new.file



0

Response Number 2
Name: jrmontg
Date: July 11, 2006 at 11:37:56 Pacific
Reply:

Thanks
that script got me this:
1000 Mbites/sec 1000 Mbites/sec
Is there a way just to get it to list it once?

jrmontg


0

Response Number 3
Name: nails
Date: July 11, 2006 at 12:26:56 Pacific
Reply:

Without seeing the output of your 'ndstat -l' command, I can't tell for sure. It looks like you have two different lines that have the same output. If that's the case, why don't you exit the awk script after the first one:

ndstat -l|awk ' { if( $1 == "Interface" && $2 == "speed:")
for(i=3; i <= NF; i++)
{
printf("%s ", $i)
if(i == NF)
exit(0)
}
} '


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Display a character n tim... Shell script encryption



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Help with a shell script

help with a modified grep script www.computing.net/answers/unix/help-with-a-modified-grep-script/4585.html

i need help with unix shell script www.computing.net/answers/unix/i-need-help-with-unix-shell-script/8239.html

Parameter file for a shell script www.computing.net/answers/unix/parameter-file-for-a-shell-script/6026.html