我是靠谱客的博主 包容人生,这篇文章主要介绍一个监控网卡流量的shell脚本,现在分享给大家,希望可以做个参考。

实现代码:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/bash eth_in_old=$(ifconfig eth0|grep "RX bytes"|sed 's/RX bytes://'|awk '{print $1}') eth_out_old=$(ifconfig eth0|grep "RX bytes"|sed 's/.*TX bytes://'|awk '{print $1}') sleep 1 eth_in_new=$(ifconfig eth0|grep "RX bytes"|sed 's/RX bytes://'|awk '{print $1}') eth_out_new=$(ifconfig eth0|grep "RX bytes"|sed 's/.*TX bytes://'|awk '{print $1}') eth_in=$(echo "scale=2;($eth_in_new - $eth_in_old)/1000.0"|bc) eth_out=$(echo "scale=2;($eth_out_new - $eth_out_old)/1000" | bc) echo "IN: $eth_in KB" echo "OUT:$eth_out KB"

输出:
[root@localhost hbshell]# ./traffic.sh

IN: 1.74 KB
OUT:1.17 KB

最后

以上就是包容人生最近收集整理的关于一个监控网卡流量的shell脚本的全部内容,更多相关一个监控网卡流量内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(159)

评论列表共有 0 条评论

立即
投稿
返回
顶部