监控网卡流量的shell脚本。
代码:
复制代码 代码示例:
#!/bin/sh
a=`cat /sys/class/net/eth0/statistics/rx_bytes`
sleep 5
b=`cat /sys/class/net/eth0/statistics/rx_bytes`
c=`echo "$b-$a"|bc`
echo "$c"
d=`echo "scale=4;$c/1000/5"|bc`
m=`echo "scale=4;$c/1000/5"|bc|cut -d "." -f 1`
if [ -z "$m" ]; then
e="0$d"
echo "$e"
else
echo "$d"
fi