记录下以前的写过的shell脚本,须要整理出各个主机的各个网卡速率,网卡名称为bond0到bond3,使用ethtool bond1命令能够查看相应网卡的速率。由于有几十台主机,因此考虑使用shell脚本去查询。shell
查询单台主机单网卡速率命令:bash
ethtool bond1 | grep Speed Speed: 20000Mb/s
查询单台主机全部bond网卡速率命令,输出网卡名称和对应的网卡速率:ssh
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网卡速率命令,能够使用ssh -tt远程执行命令:ide
ssh -tt user@192.168.1.1 "command "
须要查询的IP都在/etc/hosts文件,
文件格式:
192.168.1.1 compute-1
192.168.1.2 compute-2
筛选出192网段的IP学习
cat /etc/hosts | grep 192 | cut -d' ' -f1
使用expect自动输入密码spa
#!/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
对shell脚本格式还不太熟,脚本格式跟直接执行命令出来的结果仍是有很多区别的,仍是须要多学习shell脚本方面的知识。code