原文地址:http://yaabb163.blog.51cto.com/1975905/1350391

原脚本执行的时候有问题,拿下来改改,正常了

#!/bin/bash
#network
#Mike.Xu
while :
do
    speedtime=`date +%m"-"%d" "%k":"%M`
    speedday=`date +%m"-"%d`
    speedrx_before=`ifconfig eth0|sed -n "8"p|awk '{print $2}'|cut -c7-`
    speedtx_before=`ifconfig eth0|sed -n "8"p|awk '{print $6}'|cut -c7-`
    sleep 2
    speedrx_after=`ifconfig eth0|sed -n "8"p|awk '{print $2}'|cut -c7-`
    speedtx_after=`ifconfig eth0|sed -n "8"p|awk '{print $6}'|cut -c7-`
    speedrx_result=$[(speedrx_after-speedrx_before)/256]
    speedtx_result=$[(speedtx_after-speedtx_before)/256]
    echo "$speedday$speedtime Now_In_Speed: "$speedrx_result"kbps Now_OUt_Speed: "$speedtx_result"kbps"
    sleep 2
done