当前位置: 技术问答>linux和unix
有这么一段脚本,谁能帮我翻译一下,每行带注释。。。谢谢。
来源: 互联网 发布时间:2016-05-23
本文导语: # 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...
# 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
|
# 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 #休眠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 )) ###计算两次数据比特数,单位是M
dif_out=$((out-out_old)) #两次间隔内发送的字节数
echo " IN: ${dif_in} bytes OUT: ${dif_out} bytes " #显示到屏幕上
dif_out1=$((dif_out * 8 / 1024 / 1024 )) ##计算两次数据比特数,单位是M
echo "IN: ${dif_in1} mbps OUT: ${dif_out1} mbps" #显示到屏幕上
in_old=${in} #把本次收到的字节说保存到变量内
out_old=${out} #把本次发送的字节说保存到变量内
done
#脚本是以一秒的频率来统计上一秒内网卡收/发的数据量,并显示到屏幕上