代碼: 選擇全部
#!/bin/bash
#./ifconfig_info.sh
cards=`ifconfig | grep "Link encap" | cut -d" " -f1`
i=0
echo
for card in $cards;do
i=`expr $i + 1`
rx_bytes=`ifconfig | grep "RX bytes" | sed -n "${i}p" | grep -Eo "RX bytes:[0-9]+" | grep -Eo "[0-9]+"`
tx_bytes=`ifconfig | grep "TX bytes" | sed -n "${i}p" | grep -Eo "TX bytes:[0-9]+" | grep -Eo "[0-9]+"`
echo "device=$card, rx_bytes=$rx_bytes, tx_bytes=$tx_bytes"
done;
echo