企业级-Shell案例6——查看网卡的实时流量

查看网卡的实时流量

监控流量

脚本编写

#!/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

发布了165 篇原创文章 · 获赞 39 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/heian_99/article/details/104030173