#!/bin/bash
function Usage
{
echo "use./test_net.sh EthX Time"
echo "Are You network interface"
echo "The Last time!"
echo "For example:./test_net.sh eth0 2"
Exit
}
if [$#-lt 2-o $#-gt 2];then
usage
fi
eth=$1
time=$2
old_inbw= ' cat/proc/net/dev | grep $eth | awk-f ' [:]+ ' {print $} '
old_outbw= ' cat/proc/net/dev | grep $eth | awk-f ' [:]+ ' {print $11} '
While true
Do
Sleep $time
new_inbw= ' cat/proc/net/dev | grep $eth | awk-f ' [:]+ ' {print $} '
new_outbw= ' cat/proc/net/dev | grep $eth | awk-f ' [:]+ ' {print $11} '
inbw= ' Expr $ ((($new _inbw-$old _inbw)/$time)) '
outbw= ' Expr $ ((($new _outbw-$old _OUTBW)/$time)) '
echo "$eth: In: $inbw bytes out: $outbw bytes"
Old_inbw=${new_inbw}
OLD_OUTBW=${NEW_OUTBW}
Done
Exit 0
#./test_network.sh eth0 2
This article is from the "Broken Saber" blog, please be sure to keep this source http://90sec.blog.51cto.com/7404127/1576805
Test NIC Traffic shell script