LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-16-2006, 10:40 PM   #1
RajRed
Member
 
Registered: Mar 2005
Posts: 66

Rep: Reputation: 15
shell command to find the number of collisions of NICs


which linux command gives the number of collisions of NICs? I tried 'netstat -i' in the Redhat and did not seem to have the collision info?
Thanks.
 
Old 04-17-2006, 01:26 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
tis listed in the output of ifconfig i believe.
 
Old 04-17-2006, 03:33 AM   #3
coolb
Member
 
Registered: Apr 2006
Location: Cape Town, South Africa
Distribution: Gentoo 2006.1(2.6.17-gentoo-r7)
Posts: 222

Rep: Reputation: 30
Quote:
Originally Posted by RajRed
which linux command gives the number of collisions of NICs? I tried 'netstat -i' in the Redhat and did not seem to have the collision info?
Thanks.
hardware is better for this kind of job :-)

eg. switch or router with leds...
 
Old 04-17-2006, 03:43 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
yeah, i just love sitting in front of a switch and counting every time the collision light flicks on and off every 100th of a second!
 
Old 04-17-2006, 09:27 AM   #5
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
Would any/all of the following do what you want?
Code:
ifconfig  | grep collisions:
ifconfig  | grep packets:
ifconfig  | grep 'collisions:\|packets:'
Or, if you are sure that the interface you are interested in (eth0?) is 1st:
Code:
ifconfig  | grep collisions:              | head -1
ifconfig  | grep packets:                 | head -2
ifconfig  | grep 'collisions:\|packets:'  | head -3
 
Old 04-17-2006, 09:32 AM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
well seeing as "ifconfig eth0" shows eth0 only, a head on the output is not needed.
 
Old 04-17-2006, 07:04 PM   #7
RajRed
Member
 
Registered: Mar 2005
Posts: 66

Original Poster
Rep: Reputation: 15
But, I need to know the total number of collisions of all the NICs. Can it be done in the command line or it needs the script to do it?
 
Old 04-18-2006, 04:14 AM   #8
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
Quote:
Originally Posted by acid_kewpie
well seeing as "ifconfig eth0" shows eth0 only, a head on the output is not needed.
Oops, my bad. thanks for the reminder, I get so used to using
ifconfig on the CLI w/ tab completion (ifc<tab>) that I forget that it takes arguments.
Code:
ifconfig eth0  | grep collisions:
ifconfig eth0  | grep packets:
ifconfig eth0  | grep 'collisions:\|packets:'
Much better.


Quote:
Originally Posted by RajRed
But, I need to know the total number of collisions of all the NICs. ...
How many NIC's do you have?

Quote:
Originally Posted by RajRed
... Can it be done in the command line or it needs the script to do it?
Do you have a preference? Theoretically, anything you can do in a script, can do on the CLI. It's just not convenient.

Are you looking for a command/script that will take a list interfaces (NIC's), find their collision counts, add up those counts, & output that sum? And do you want verbiage, like "Total collisions for interfaces eth0 & eth1 = nnn"?
 
Old 04-18-2006, 08:22 AM   #9
RajRed
Member
 
Registered: Mar 2005
Posts: 66

Original Poster
Rep: Reputation: 15
yes, I need to just print the total number of collision of all NICs. The number of NICs should be another variable too.

Thanks.
 
Old 04-18-2006, 12:42 PM   #10
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
Good. Unless the NIC's are consecutively #'d, you will need to supply a list of their names rather than a count; the list could be permanent. Perhaps a little more background on what you will be doing, especially how it might change from 1 use to the next.

Now for the big Q: how good are you at bash scripting & how much help do need in writing it?
 
Old 04-18-2006, 02:08 PM   #11
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,499
Blog Entries: 2

Rep: Reputation: 68
You don't mention which RedHat are you using, but the code bellow is good for FC5. I think it will work in any kernel 2.6, because it depends on /sys interface only.

Code:
for device in $(\ls /sys/class/net); do 
   echo -n "${device}: "; 
   cat /sys/class/net/${device}/statistics/collisions; 
   echo; 
done

Last edited by marozsas; 04-18-2006 at 02:10 PM.
 
Old 04-18-2006, 03:39 PM   #12
RajRed
Member
 
Registered: Mar 2005
Posts: 66

Original Poster
Rep: Reputation: 15
I think I understand the logic here, it still list the collision for each nic, how do I get the sum of all the collisions?

Thanks.
 
Old 04-19-2006, 06:13 AM   #13
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,499
Blog Entries: 2

Rep: Reputation: 68
Just put the intermediate collision info in a variable and add it to a total count variable. At the end, print the total.

Take a look at this great bash tutorial. It has all stuff you need to learn to mastering shell script: http://www.tldp.org/LDP/abs/html/

enjoy,

Code:
for device in $(\ls /sys/class/net); do
     echo -n "${device}: ";  
     col=$(cat /sys/class/net/${device}/statistics/collisions); 
     sum=$(($sum+$col)); 
     echo $col;   
done
echo "sum: $sum"
 
Old 04-19-2006, 11:24 AM   #14
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
Using /sys/class/net/${device}/statistics/collisions is a vast improvement over my technique. Tip of the hat to marozsas.

You can still change the source of the iterated values for ${device} from $(\ls /sys/class/net), which will list all interfaces, to a list of the NIC's only -- if you want to.

You could also pipe the output through awk to format it in columns. Depends on how pretty you want it.
 
Old 04-19-2006, 01:20 PM   #15
RajRed
Member
 
Registered: Mar 2005
Posts: 66

Original Poster
Rep: Reputation: 15
Thank you for your suggestions.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 07:42 AM
problem with the shell command "find zosimus Linux - Software 7 06-14-2005 04:28 PM
number of command line arguments to shell u4u Linux - General 1 03-04-2005 06:09 PM
Extracting the line number in Unix Shell? Aziz Programming 2 12-01-2004 11:03 AM
"how do I extract a number from a text file using shell command?" sdandeker Linux - Networking 3 02-12-2004 08:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration