LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   shell command to find the number of collisions of NICs (https://www.linuxquestions.org/questions/linux-newbie-8/shell-command-to-find-the-number-of-collisions-of-nics-435823/)

RajRed 04-16-2006 10:40 PM

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.

acid_kewpie 04-17-2006 01:26 AM

tis listed in the output of ifconfig i believe.

coolb 04-17-2006 03:33 AM

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...

acid_kewpie 04-17-2006 03:43 AM

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

archtoad6 04-17-2006 09:27 AM

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


acid_kewpie 04-17-2006 09:32 AM

well seeing as "ifconfig eth0" shows eth0 only, a head on the output is not needed.

RajRed 04-17-2006 07:04 PM

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?

archtoad6 04-18-2006 04:14 AM

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"?

RajRed 04-18-2006 08:22 AM

yes, I need to just print the total number of collision of all NICs. The number of NICs should be another variable too.

Thanks.

archtoad6 04-18-2006 12:42 PM

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?

marozsas 04-18-2006 02:08 PM

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


RajRed 04-18-2006 03:39 PM

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.

marozsas 04-19-2006 06:13 AM

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"


archtoad6 04-19-2006 11:24 AM

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.

RajRed 04-19-2006 01:20 PM

Thank you for your suggestions.


All times are GMT -5. The time now is 11:09 PM.