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. |
tis listed in the output of ifconfig i believe.
|
Quote:
eg. switch or router with leds... |
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! :D
|
Would any/all of the following do what you want?
Code:
ifconfig | grep collisions: Code:
ifconfig | grep collisions: | head -1 |
well seeing as "ifconfig eth0" shows eth0 only, a head on the output is not needed.
|
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?
|
Quote:
ifconfig on the CLI w/ tab completion (ifc<tab>) that I forget that it takes arguments. Code:
ifconfig eth0 | grep collisions: Quote:
Quote:
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"? |
yes, I need to just print the total number of collision of all NICs. The number of NICs should be another variable too.
Thanks. |
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? |
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 |
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. |
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 |
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. |
Thank you for your suggestions.
|
All times are GMT -5. The time now is 11:09 PM. |