Skip to content

Instantly share code, notes, and snippets.

@Cellane
Created December 1, 2010 15:29
Show Gist options
  • Save Cellane/723633 to your computer and use it in GitHub Desktop.
Save Cellane/723633 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
echo "Refresh interval in seconds: "
read interval
function received () {
local received=`netstat -s -p tcp | grep 'acks' | grep 'bytes' | awk '{ print $4 }'`
echo "${received}"
}
function sent () {
local sent=`netstat -s -p tcp | grep 'data packets' | grep -v 'retransmitted' | awk '{ print $4 }' | sed 's/(//'`
echo "${sent}"
}
received=0
sent=0
while [ true ]; do
clear
received=$(( `received` - $received))
sent=$(( `sent` - $sent))
echo "Received ${received} bytes since last refresh ($(( ${received} / 1024 / 1024 )) megabytes)."
echo "Sent ${sent} bytes since last refresh ($(( ${sent} / 1024 / 1024 )) megabytes)."
received=$(received)
sent=$(sent)
echo
for ((i=0; i<$interval; i+=1)); do
remaining=$(( $interval - $i ));
echo -en "Next refresh in ${remaining} second(s).\015"
sleep 1
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment