Augustus SFX van Dusen <(E-Mail Removed)> wrote:
>On Tue, 21 Jun 2005 21:24:38 +0000, Augustus SFX van Dusen wrote:
>
>> I am looking for a tool that tells me how many bytes have been
>> transferred over a specified network interface, between two given points
>> in time. Anybody know about such a thing?
>
> Let me add that I'd be interested in a simple command-line tool, that
>when stopped spits out the number of bytes transferred since it was
>launched. Things like ntop, while nice, do much more than I require, and
>what I require they do in ways which are not practical for my purposes.
Here's a shell script that does what you ask, I think. If
invoked as "foo eth0", it will run until you kill it, and then
will exit showing the bytes rcvd and sent on the eth0 interface.
If invoked as "foo eth10 10" if will run for 10 seconds, and
stop on its own. (The interval must be within the range that
bash's sleep function can handle.)
Typical output looks like this:
#./foo eth0 10
eth0: 13251 bytes rcvd, 5451 bytes sent.
#!/bin/bash
trap showresults exit
iface="${1}"
interval=${2}
showresults () {
if [ ${retval} -ne 0 ] ; then
exit ${retval}
fi
rstart=${rbytes}
tstart=${tbytes}
get_data
echo -n "$iface: $(expr $rbytes - $rstart) bytes rcvd, "
echo "$(expr $tbytes - $tstart) bytes sent."
}
get_data () {
IFS=" :"
while read if rbytes a b c d e f g tbytes junk ; do
if [ "${if}" = "${iface}" ] ; then break; fi
done < /proc/net/dev
}
retval=1;
if [ ${#} -lt 1 ] ; then
echo ""
echo "Error: no interface name specified"
echo "Usage: $0 interface [ seconds ]"
echo ""
exit ${retval}
fi
get_data
if [ "${if}" != "${iface}" ] ; then
echo "Error: No data for interface $iface"
exit 1
fi
retval=0
if [ ${#} -gt 1 ] ; then
sleep ${interval}
else
while true ; do
sleep 100
done
fi
# end of script file
--
Floyd L. Davidson <http://web.newsguy.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska)
(E-Mail Removed)