下面是乙個測試網絡卡流量的指令碼,指令碼內容如下:
#!/bin/bash
function usage
if [ $# -lt 2 -o $# -gt 2 ];then
usage
fieth=$1
time=$2
old_inbw=`cat /proc/net/dev | grep $eth | awk -f'[: ]+' ''`
old_outbw=`cat /proc/net/dev | grep $eth | awk -f'[: ]+' ''`
while true
dosleep $time
new_inbw=`cat /proc/net/dev | grep $eth | awk -f'[: ]+' ''`
new_outbw=`cat /proc/net/dev | grep $eth | awk -f'[: ]+' ''`
inbw=`expr $((($new_inbw-$old_inbw)/$time))`
outbw=`expr $((($new_outbw-$old_outbw)/$time))`
echo "$eth: in:$inbw bytes out:$outbw bytes"
old_inbw=$
old_outbw=$
done
exit 0
執行效果:
[root@bogon shell]# ./test_net.sh eth0 2
eth0: in:3097 bytes out:50374 bytes
eth0: in:3158 bytes out:44202 bytes
eth0: in:2587 bytes out:58932 bytes
eth0: in:2104 bytes out:51543 bytes
文章出處:飛諾網(www.diybl.com):
網絡卡流量監控指令碼
sar n dev 1 2 sar命令包含在sysstat工具包中,提供系統的眾多統計資料。命令後面1 2 意思是 每一秒鐘取1次值,取2次。dev顯示網路介面資訊 另外,n引數很有用,他有6個不同的開關 dev edev nfs nfsd sock all 其代表的含義如下 dev顯示網路介面資訊...
檢視網絡卡流量的小指令碼
filename flow.sh bin bash while 1 doeth 1 rxpre cat proc net dev grep eth tr awk txpre cat proc net dev grep eth tr awk sleep 1 rxnext cat proc net de...
Python指令碼實現網絡卡流量監控
usr bin env python coding utf 8 import sys,re,time,os maxdata 50000 單位kb memfilename tmp newnetcardtransdata.txt netcard proc net dev def checkfile fi...