前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >shell脚本 监控网络流量

shell脚本 监控网络流量

作者头像
用户2458545
发布2022-09-07 11:28:45
3.8K0
发布2022-09-07 11:28:45
举报
文章被收录于专栏:阿牛的牙
shell脚本 监控网络流量
shell脚本 监控网络流量

实时监控网络出入流量

代码语言:javascript
复制
#!/bin/bash 

if [ -n "${1}" ];
        then 
    NetDevice=${1};
else 
    NetDevice=eth0;
fi 
    printf "|------ Time  ------|---- NetIn ----|--- NetOUt ----|\n" 
while true 
    do time=$(date +%F" "%T) 
        rx_before=$(ifconfig ${NetDevice}|awk -F' *|:' '{if($2=="RX"&&$3=="bytes") print $4}') 
        tx_before=$(ifconfig ${NetDevice}|awk -F' *|:' '{if($2=="RX"&&$3=="bytes") print $9}')
     sleep 1 
        rx_after=$(ifconfig ${NetDevice}|awk -F' *|:' '{if($2=="RX"&&$3=="bytes") print $4}') 
        tx_after=$(ifconfig ${NetDevice}|awk -F' *|:' '{if($2=="RX"&&$3=="bytes") print $9}') 
        rx_result=$(((rx_after-rx_before)/1024)) 
        tx_result=$(((tx_after-tx_before)/1024)) 
printf "|%19s|%10s kbps|%10s kbps|\n" "${time}" "${rx_result}" "${tx_result}"
 # sleep 1 
done
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019年1月31日 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档