统计网络流量

分享一个脚本统计网络流量:

#!/bin/bash
# Almost everything of this is shamelessly copied from
# http://www.lugmen.org.ar/~conan/tmp/wmii/status


while true; do
    RX0=`/bin/grep eth0 /proc/net/dev | tr ':' ' ' | awk {'print $2'}`
    TX0=`/bin/grep eth0 /proc/net/dev | tr ':' ' ' | awk {'print $10'}`
    sleep 2
    RX1=`/bin/grep eth0 /proc/net/dev | tr ':' ' ' | awk {'print $2'}`
    TX1=`/bin/grep eth0 /proc/net/dev | tr ':' ' ' | awk {'print $10'}`
    RX="$(((RX1-RX0)/2048))"
    TX="$(((TX1-TX0)/2048))"


    RX="DOWN `printf %3d $RX`KB/s"
    TX="UP   `printf %3d $TX`KB/s"


    echo "$RX $TX"
done


你可能感兴趣的:(linux,bash,网络流量)