Linux读取网卡流量脚本
2012-01-03 11:09
239 查看
此脚本是在linux中读取网卡每秒钟的实时流量。
创建脚本net.sh
复制一下脚本内容到文件中,保存.
Chmod +x net.sh 赋予执行权限。
运行 ./net.sh etch0
Eth0是所要监控的网卡。
代码内容如下:
#!/bin/bash
#eval `date "+day=%d; month=%m; year=%Y; hour=%H; minute=%M second=%S"`
#INSTFIL="$year-$month-$day $hour:$minute:$second"
#INSTFIL1="$year-$month-$day"
#INSTFIL2="$hour:$minute"
#INSTFIL3="$month-$day"
#INSTFIL4="$hour:$minute:$second"
R2=`cat /sys/class/net/$1/statistics/rx_bytes`
T2=`cat /sys/class/net/$1/statistics/tx_bytes`
NUM=100000
if [ -z "$1" ]; then
echo
echo usage: $0 network-interface
echo
echo e.g. $0 eth0
echo
exit
fi
IF=$1
while true
do
R1=`cat /sys/class/net/$1/statistics/rx_bytes`
T1=`cat /sys/class/net/$1/statistics/tx_bytes`
TBPS=`expr $T1 - $T2`
RBPS=`expr $R1 - $R2`
TKBPS=`expr $TBPS / 100`
RKBPS=`expr $RBPS / 100`
RKBPS1=`echo "scale=3; $RBPS/$NUM"|bc`
eval `date "+day=%d; month=%m; year=%Y; hour=%H; minute=%M second=%S"`
INSTFIL4="$hour:$minute:$second"
echo "$INSTFIL4 tx $1: $TKBPS KB/ rx $RKBPS kb/s 0$RKBPS1 bits/s"
R2=`cat /sys/class/net/$1/statistics/rx_bytes`
T2=`cat /sys/class/net/$1/statistics/tx_bytes`
sleep 1s
done本文出自 “随风奔跑-运维” 博客,请务必保留此出处http://lzf8989.blog.51cto.com/697220/756812
创建脚本net.sh
复制一下脚本内容到文件中,保存.
Chmod +x net.sh 赋予执行权限。
运行 ./net.sh etch0
Eth0是所要监控的网卡。
代码内容如下:
#!/bin/bash
#eval `date "+day=%d; month=%m; year=%Y; hour=%H; minute=%M second=%S"`
#INSTFIL="$year-$month-$day $hour:$minute:$second"
#INSTFIL1="$year-$month-$day"
#INSTFIL2="$hour:$minute"
#INSTFIL3="$month-$day"
#INSTFIL4="$hour:$minute:$second"
R2=`cat /sys/class/net/$1/statistics/rx_bytes`
T2=`cat /sys/class/net/$1/statistics/tx_bytes`
NUM=100000
if [ -z "$1" ]; then
echo
echo usage: $0 network-interface
echo
echo e.g. $0 eth0
echo
exit
fi
IF=$1
while true
do
R1=`cat /sys/class/net/$1/statistics/rx_bytes`
T1=`cat /sys/class/net/$1/statistics/tx_bytes`
TBPS=`expr $T1 - $T2`
RBPS=`expr $R1 - $R2`
TKBPS=`expr $TBPS / 100`
RKBPS=`expr $RBPS / 100`
RKBPS1=`echo "scale=3; $RBPS/$NUM"|bc`
eval `date "+day=%d; month=%m; year=%Y; hour=%H; minute=%M second=%S"`
INSTFIL4="$hour:$minute:$second"
echo "$INSTFIL4 tx $1: $TKBPS KB/ rx $RKBPS kb/s 0$RKBPS1 bits/s"
R2=`cat /sys/class/net/$1/statistics/rx_bytes`
T2=`cat /sys/class/net/$1/statistics/tx_bytes`
sleep 1s
done本文出自 “随风奔跑-运维” 博客,请务必保留此出处http://lzf8989.blog.51cto.com/697220/756812
相关文章推荐
- Linux读取网卡流量脚本
- linux shell awk实现实时监控网卡流量脚本
- linux查看网卡平均流量的脚本
- LINUX下查看网卡流量的脚本(完美修改版)【转】
- linux 统计网卡流量小脚本
- Linux通过shell脚本计算网卡流量
- linux下监控网卡流量的shell脚本
- 三个监控linux网卡流量脚本
- 实时查看linux网卡流量脚本
- linux 网卡流量监控脚本
- 计算Linux网卡流量的脚本
- shell脚本助你在linux下实时查看单网卡流量
- linux 查看网卡流量的脚本
- linux查看网卡流量的脚本
- linux下监视网卡流量的一段脚本
- Linux下网络流量监控工具大全,查看网卡的实时流量脚本
- linux网卡流量监控脚本
- linux 查看网卡流量的shell脚本
- linux 监控网卡流量
- linux-分析网卡流量