欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

shell腳本輸出多個(gè)主機(jī)的網(wǎng)卡速率的方法

 更新時(shí)間:2019年12月19日 10:45:01   作者:Eddy72  
這篇文章主要介紹了shell腳本輸出多個(gè)主機(jī)的網(wǎng)卡速率的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

背景:

記錄下之前的寫過(guò)的shell腳本,需要整理出各個(gè)主機(jī)的各個(gè)網(wǎng)卡速率,網(wǎng)卡名稱為bond0到bond3,使用ethtool bond1命令可以查看相應(yīng)網(wǎng)卡的速率。因?yàn)橛袔资_(tái)主機(jī),所以考慮使用shell腳本去查詢。

具體思路:

查詢單臺(tái)主機(jī)單網(wǎng)卡速率命令:

ethtool bond1 | grep Speed
Speed: 20000Mb/s

查詢單臺(tái)主機(jī)所有bond網(wǎng)卡速率命令,輸出網(wǎng)卡名稱和對(duì)應(yīng)的網(wǎng)卡速率:

for i in {0..3};do echo bond$i `/usr/sbin/ethtool bond$i 2 > /dev/null | grep Speed`;done
bond0
bond1 Speed: 20000Mb/s
bond2 Speed: 20000Mb/s
bond3 Speed: 2000Mb/s

查詢遠(yuǎn)程主機(jī)所有bond網(wǎng)卡速率命令,可以使用ssh -tt遠(yuǎn)程執(zhí)行命令:

ssh -tt user@192.168.1.1 "command "

需要查詢的IP都在/etc/hosts文件,
文件格式:

  • 192.168.1.1 compute-1
  • 192.168.1.2 compute-2

篩選出192網(wǎng)段的IP

cat /etc/hosts | grep 192 | cut -d' ' -f1

使用expect自動(dòng)輸入密碼

完整腳本:

#!/bin/bash
cat /etc/hosts | grep 192 | while read line
do
echo $line
ip=`echo $line | cut -d' ' -f1`
/usr/bin/expect <<-EOF
spawn ssh -tt user@$ip "for i in {0..3};do echo bond\$\i \`/usr/sbin/ethtool bond\$\i 2>/dev/null | grep Speed\`;done "
expect {
    "(yes/no)?" { send "yes\n";exp_continue }
    "*assword:" { send "password\n";}
}
expect eof
EOF
done

總結(jié)

對(duì)shell腳本格式還不太熟,腳本格式跟直接執(zhí)行命令出來(lái)的結(jié)果還是有不少區(qū)別的,還是需要多學(xué)習(xí)shell腳本方面的知識(shí)。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論