Get the App
SLTechnology News&Howtos  ›  Servers  › 

The shell script outputs the network card rate of multiple hosts

Shulou Source: shulou.com Published: 2022-06-02 12:37:38 10月02日 Update

Background:

To record the previously written shell script, you need to sort out the speed of each network card of each host. The name of the network card is bond0 to bond3. You can use the ethtool bond1 command to check the speed of the corresponding network card. Because there are dozens of hosts, consider using the shell script to query.

Specific ideas:

Query the speed command of single host and single network card:

Ethtool bond1 | grep SpeedSpeed: 20000Mb/s

Query all bond network card rate commands of a single host, and output the network card name and the corresponding network card rate:

For i in {0.3}; do echo bond$i `/ usr/sbin/ethtool bond$i 2 > / dev/null | grep Speed`; donebond0bond1 Speed: 20000Mb/sbond2 Speed: 20000Mb/sbond3 Speed: 2000Mb/s

To query all bond Nic rate commands of a remote host, you can use ssh-tt to remotely execute commands:

Ssh-tt user@192.168.1.1 "command"

All the IP to be queried are in the / etc/hosts file

File format:

192.168.1.1 compute-1

192.168.1.2 compute-2

Filter out the IP of 192 network segments

Cat / etc/hosts | grep 192 | cut-d'-F1

Use expect to enter passwords automatically

Complete script: #! / bin/bashcat / etc/hosts | grep 192 | while read linedoecho $lineip= `echo $line | cut-d''- f1` / usr/bin/expect

Tags: Network card script speed command host query format name file or output password idea aspect knowledge result network segment background selection learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno NVidia Shulou Tech Info Docker Apple