检测网卡流量
#!/bin/bash
NIC=$1
echo In ------ Out
while true; do
OLD_IN=$(cat /proc/net/dev | awk '/eth0/{print $2}')
OLD_OUT=$(cat /proc/net/dev | awk '/eth0/{print $10}')
sleep 1
NEW_IN=$(cat /proc/net/dev | awk '/eth0/{print $2}')
NEW_OUT=$(cat /proc/net/dev | awk '/eth0/{print $10}')
IN=$(printf ""%.1f%s" $((($NEW_IN-$OLD_IN)/1024)), "KB/s")
OUT=$(printf ""%.1f%s" $((($NEW_OUT-$OLD_OUT)/1024)), "KB/s")
echo "$IN $OUT"
sleep 1
done