#!/bin/bash

ETH=eth0
while : ; do
        time=`date +%m"-"%d" "%k":"%M`
        day=`date +%m"-"%d`
        rx_before=`ifconfig $ETH|sed -n "8"p|awk '{print $2}'|cut -c7-`
        tx_before=`ifconfig $ETH|sed -n "8"p|awk '{print $6}'|cut -c7-`
        sleep 2
        rx_after=`ifconfig $ETH|sed -n "8"p|awk '{print $2}'|cut -c7-`
        tx_after=`ifconfig $ETH|sed -n "8"p|awk '{print $6}'|cut -c7-`
        rx_result=$[(rx_after-rx_before)/256]
        tx_result=$[(tx_after-tx_before)/256]
        echo "$time Now_In_Speed: "$rx_result"kbps Now_OUt_Speed: "$tx_result"kbps"
        sleep 2
done
执行结果:
[root@localhost ~]# ./net.sh 
11-29 22:06 Now_In_Speed: 7173kbps Now_OUt_Speed: 26691kbps
11-29 22:06 Now_In_Speed: 6228kbps Now_OUt_Speed: 30047kbps
11-29 22:06 Now_In_Speed: 2310kbps Now_OUt_Speed: 34677kbps
11-29 22:06 Now_In_Speed: 3092kbps Now_OUt_Speed: 36550kbps
11-29 22:06 Now_In_Speed: 8447kbps Now_OUt_Speed: 33395kbps