背景:
記錄下之前的寫過的shell腳本,需要整理出各個主機的各個網卡速率,網卡名稱為bond0到bond3,使用ethtool bond1命令可以查看相應網卡的速率。因為有幾十臺主機,所以考慮使用shell腳本去查詢。
具體思路:
查詢單臺主機單網卡速率命令:
ethtool bond1 | grep SpeedSpeed: 20000Mb/s
查詢單臺主機所有bond網卡速率命令,輸出網卡名稱和對應的網卡速率:
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
查詢遠程主機所有bond網卡速率命令,可以使用ssh -tt遠程執行命令:
ssh -tt [email protected] "command "
需要查詢的IP都在/etc/hosts文件,
文件格式:
篩選出192網段的IP
cat /etc/hosts | grep 192 | cut -d' ' -f1
使用expect自動輸入密碼
完整腳本:
#!/bin/bashcat /etc/hosts | grep 192 | while read linedoecho $lineip=`echo $line | cut -d' ' -f1`/usr/bin/expect <<-EOFspawn 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 eofEOFdone
總結
對shell腳本格式還不太熟,腳本格式跟直接執行命令出來的結果還是有不少區別的,還是需要多學習shell腳本方面的知識。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。
新聞熱點
疑難解答