#!/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 ~]# ./test.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
11-29 22:06 Now_In_Speed: 6733kbps Now_OUt_Speed: 31551kbps
11-29 22:06 Now_In_Speed: 2290kbps Now_OUt_Speed: 23405kbps
11-29 22:06 Now_In_Speed: 2199kbps Now_OUt_Speed: 32412kbps
11-29 22:06 Now_In_Speed: 2177kbps Now_OUt_Speed: 43927kbps
11-29 22:06 Now_In_Speed: 2969kbps Now_OUt_Speed: 40057kbps
11-29 22:06 Now_In_Speed: 2062kbps Now_OUt_Speed: 32435kbps
11-29 22:06 Now_In_Speed: 1557kbps Now_OUt_Speed: 27812kbps
说明:结果还是比较准确的,和cacti的监控流量查不多,如果想暂时统计当前网络的流量,比较实用!
阅读(2979) | 评论(0) | 转发(1) |