linux查看网口流量的脚本
来源:互联网 发布:oppor9下载不了软件 编辑:程序博客网 时间:2024/04/30 16:52
linux查看网口流量的脚本
通过本脚本,发现bash确实在算术运算方面比老的shell要强大,为此需要开始学习bash,以利用它强大的功能。不过bash中的for语句功能和c中差异比较大。
# cat stream
#! /bin/bash
# Write by Neil.xu qq:37391319 email: xurongzhong@gmail.com
# 2008-8-19 we need to monitor streams of LTS channels, so write this script
typeset in in_old dif_in dif_in1 dif_out1
typeset out out_old dif_out
in_old=$(cat /proc/net/dev | grep eth0 | sed 's=^.*:==' | awk '{ print $1 }' )
out_old=$(cat /proc/net/dev | grep eth0 | sed 's=^.*:==' | awk '{ print $9 }')
while true
do
sleep 1
in=$(cat /proc/net/dev | grep eth0 | sed 's=^.*:==' | awk '{ print $1 }')
out=$(cat /proc/net/dev | grep eth0 | sed 's=^.*:==' | awk '{ print $9 }')
dif_in=$((in-in_old))
dif_in1=$((dif_in * 8 / 1024 / 1024 ))
dif_out=$((out-out_old))
echo " IN: ${dif_in} bytes OUT: ${dif_out} bytes "
dif_out1=$((dif_out * 8 / 1024 / 1024 ))
echo "IN: ${dif_in1} mbps OUT: ${dif_out1} mbps"
in_old=${in}
out_old=${out}
done
运行效果:
# ./stream
IN: 349179 bytes OUT: 1363936 bytes
IN: 2 mbps OUT: 10 mbps
IN: 349612 bytes OUT: 1361852 bytes
IN: 2 mbps OUT: 10 mbps
IN: 348684 bytes OUT: 1358952 bytes
IN: 2 mbps OUT: 10 mbps
IN: 349998 bytes OUT: 1359092 bytes
# cat stream
#! /bin/bash
# Write by Neil.xu qq:37391319 email: xurongzhong@gmail.com
# 2008-8-19 we need to monitor streams of LTS channels, so write this script
typeset in in_old dif_in dif_in1 dif_out1
typeset out out_old dif_out
in_old=$(cat /proc/net/dev | grep eth0 | sed 's=^.*:==' | awk '{ print $1 }' )
out_old=$(cat /proc/net/dev | grep eth0 | sed 's=^.*:==' | awk '{ print $9 }')
while true
do
sleep 1
in=$(cat /proc/net/dev | grep eth0 | sed 's=^.*:==' | awk '{ print $1 }')
out=$(cat /proc/net/dev | grep eth0 | sed 's=^.*:==' | awk '{ print $9 }')
dif_in=$((in-in_old))
dif_in1=$((dif_in * 8 / 1024 / 1024 ))
dif_out=$((out-out_old))
echo " IN: ${dif_in} bytes OUT: ${dif_out} bytes "
dif_out1=$((dif_out * 8 / 1024 / 1024 ))
echo "IN: ${dif_in1} mbps OUT: ${dif_out1} mbps"
in_old=${in}
out_old=${out}
done
运行效果:
# ./stream
IN: 349179 bytes OUT: 1363936 bytes
IN: 2 mbps OUT: 10 mbps
IN: 349612 bytes OUT: 1361852 bytes
IN: 2 mbps OUT: 10 mbps
IN: 348684 bytes OUT: 1358952 bytes
IN: 2 mbps OUT: 10 mbps
IN: 349998 bytes OUT: 1359092 bytes
- linux查看网口流量的脚本
- linux 查看网卡流量的shell脚本
- linux 查看网卡流量的脚本
- linux查看网卡平均流量的脚本
- Linux 中查看网口流量的利器 -- sar
- Linux 中查看网口流量的利器 -- sar
- 实时查看linux网卡流量脚本
- 实时查看Linux网卡流量Shell脚本
- shell 脚本查看流量
- LINUX下查看网卡流量的脚本(完美修改版)【转】
- Linux 各种查看网卡流量的方法
- Linux下查看网卡流量的工具
- linux 上查看服务器的流量
- 如何查看linux的实时流量带宽
- linux查看网卡流量的一些方法
- Linux 各种查看网卡流量的方法
- linux iftop查看流量的方法
- linux下如何查看网卡的流量
- OracleDBA+性能优化8日游笔记——第二天(二)之Oracle体系架构详解
- 对象间的联动——观察者模式(五)
- Linux下的压缩解压缩命令详解
- linux常用+经典命令
- 嵌入式工程师C语言面试常见的0x10个问题
- linux查看网口流量的脚本
- 解密微软失落十年:官僚主义盛行 错过社交网络
- 保护模式与实模式的切换
- Objective-c 类的继承 方法重写 方法重载
- UVaOJ 572 - Oil Deposits
- SYSENTER指令相关(精华学习)
- Java学习
- 今天开通博客了
- 对象间的联动——观察者模式(六)