#!/bin/bash # (CC) 1998 Ken Chase, math@sizone.org and others # for freebsd, needs tweaks for linux if [ -z "$1" ]; then echo "usage: $0 (interface) [delay]" exit fi d=10 if [ -n "$2" ]; then d=$2 fi echo " TIME | IN | OUT | TOTAL" while true; do echo `netstat -Wnib | grep $1 | grep Link | head -1; date +%H%M%S` | gawk '{ print $5,$6,$7,$8,$9,$10,$12}' #$1 $2 $3 $4 $5 $6 $7 sleep $d done | gawk '{ lasttime2=systime(); if (lki) { delay=lasttime2-lasttime; lasttime=lasttime2; div=delay*1000; pin =int(($1-lpi)/delay); ein =int(($2-lei)/delay); kin =int(($3-lki)/div); bin =kin * 8; pout=int(($4-lpo)/delay); eout=int(($5-leo)/delay); kout=int(($6-lko)/div); bout=kout * 8; #bytes per packet if ($1-lpi) { bppi=int(($3-lki)/($1-lpi)); } else { bppi="n/a" } if ($4-lpo) { bppo=int(($6-lko)/($4-lpo)); } else { bppo="n/a" } printf("%6i|%6iKbps %5ipps %4iB/p | %6iKbps %5ipps %4iB/p | %7iKbps\n", $7, bin, pin, bppi, bout, pout, bppo, bin+bout) } lpi=$1;lei=$2;lki=$3; lpo=$4;leo=$5;lko=$6 }'