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

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

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

背景:

記錄下之前的寫過的shell腳本,需要整理出各個主機的各個網(wǎng)卡速率,網(wǎng)卡名稱為bond0到bond3,使用ethtool bond1命令可以查看相應(yīng)網(wǎng)卡的速率。因為有幾十臺主機,所以考慮使用shell腳本去查詢。

具體思路:

查詢單臺主機單網(wǎng)卡速率命令:

ethtool bond1 | grep Speed
Speed: 20000Mb/s

查詢單臺主機所有bond網(wǎng)卡速率命令,輸出網(wǎng)卡名稱和對應(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

查詢遠程主機所有bond網(wǎng)卡速率命令,可以使用ssh -tt遠程執(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自動輸入密碼

完整腳本:

#!/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é)

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

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

相關(guān)文章

最新評論