统计流入流出流量

目录

脚本

#!/bin/bash
eth0=$1
echo  -e    "流量进入--流量传出    "
while true; do
        old_in=$(cat /proc/net/dev |grep $eth0 |awk '{print $2}')
        old_out=$(cat /proc/net/dev |grep $eth0 |awk '{print $10}')
        sleep 1
        new_in=$(cat /proc/net/dev |grep $eth0 |awk '{print $2}')
        new_out=$(cat /proc/net/dev |grep $eth0 |awk '{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"
done

测试

[root@dy1 ~]# /bin/bash 4.sh eth0
流量进入--流量传出    
0.0KB/s 0.0KB/s
0.0KB/s 0.0KB/s
0.0KB/s 0.0KB/s
0.0KB/s 0.0KB/s
0.0KB/s 0.0KB/s
0.0KB/s 0.0KB/s
0.0KB/s 0.0KB/s
0.0KB/s 0.0KB/s

猜你喜欢

转载自www.cnblogs.com/yizhangheka/p/12747098.html