这个脚本主要收集接口名称、状态、IP、绑定接口。
脚本如下
#!/bin/bash
# By Nick.Ma
#ETH_MAX=$(cat /etc/udev/rules.d/70-persistent-net.rules | grep -v "^#" | grep -c "eth*")
ETH_NAME=$(cat /etc/udev/rules.d/70-persistent-net.rules | grep -v "^#" | awk -F "," '{print $8}' | cut -c 8-11 | grep -v "^$")
let IFACE_L_MAX=$(cat /etc/network/interfaces | grep -v "^#" | grep -A 7 "^auto br" -c )-1
let IFACE_B_MAX=$(cat /etc/network/interfaces | grep -v "^#" | grep -A 7 "^auto bond" -c )-1
echo -e "Name\tState\tAddress\t\tRelated-Iface"
for i in ${ETH_NAME} #${IFACE_L_NAME}
do
IFACE_STATE=$(ip link | grep "$i" | awk -F "," '{print $3}' )
IFACE_IP=$(cat /etc/network/interfaces | sed '/iface '"$i"'/{n;s/address//p}' -n | grep -v "^$")
echo -e "$i\t$IFACE_STATE\b$IFACE_IP"
done
for i in $( seq 0 $IFACE_L_MAX )
do
#IFACE_Br_NAME=$(ip link | grep br$i | awk -F "," '{print $3}')
IFACE_Br_STATE=$(ip link | grep br$i | grep -v "vir" | awk -F "," '{print $3}' | grep -v "^$" )
IFACE_Br_IP=$(cat /etc/network/interfaces | grep -v "^#" | grep -A 7 "^auto br$i" | awk '$1~/address/{print $2}')
BR_R_IFACE=$(cat /etc/network/interfaces | grep -v "^#" | grep -A 7 "^auto br$i" | awk '$1~/bridge_ports/{print $2" "$3}')
echo -e "br$i\t$IFACE_Br_STATE\t$IFACE_Br_IP\t$BR_R_IFACE"
done
for i in $( seq 0 $IFACE_B_MAX )
do
#IFACE_BOND_NAME=$(ip link | grep bond$i | awk -F "," '{print $3}')
IFACE_BOND_STATE=$(ip link | grep bond$i | awk -F "," '{print $3}' | grep -v "^$" )
IFACE_BOND_IP=$(cat /etc/network/interfaces | grep -v "^#" | grep -A 7 "^auto bond$i" | awk '$1~/address/{print $2}')
BOND_R_IFACE=$(cat /etc/network/interfaces | grep -v "^#" | grep -A 7 "^auto bond$i" | awk '$1~/post-up/{print $4" "$5}')
if [ "$IFACE_BOND_STATE" == "UP" ] ; then
echo -e "bond$i\t$IFACE_BOND_STATE\t$IFACE_BOND_IP\t$BOND_R_IFACE"
else
echo -e "bond$i\t$IFACE_BOND_IP\t\t\t$BOND_R_IFACE"
fi
done
结果如下:
Name State Address Related-Iface
eth1
eth2
eth3
eth0 UP 172.30.39.7
br0 UP 172.30.39.89 bond0
bond0 eth2 eth3
阅读(879) | 评论(0) | 转发(0) |