netstat -I <interface> 1
, e.g. netstat -I fxp0 1
This one's my favorite, but I usually add a number at the end (ale said:$ systat -ifstat
% systat -ifstat x
) to get updates every x seconds.I do this too. And almost always x=1.Beastie said:This one's my favorite, but I usually add a number at the end (% systat -ifstat x
) to get updates every x seconds.
Sorry If I bump, but I need too something that I can grab in a script, any advice?Does anyone know of a way to get the current up/down rate for an interface without the curses interface? I would like the current rates reported once, so I can grab these values in a script.
Sorry If I bump, but I need too something that I can grab in a script, any advice?
netstat -I <iface>
How can I grep and awk download/upload speed? I need it for a status barnetstat -I <iface>
ifstart -b 1 1 | tail -n 1
And If I want to visualize download or upload only?Dear wesbl,
you could use net/ifstat and run
It reports the speed in kbit/s once in the last line which is taken by tail. I use it like that.Code:ifstart -b 1 1 | tail -n 1
For just the download rate, you can useAnd If I want to visualize download or upload only?
ifstat -i wlan0 -b 1 1 | awk 'NR%3==0 {print $1}'
. For upload only, replace $1 with $2. Replace wlan0 with your interface.For just the download rate, you can useifstat -i wlan0 -b 1 1 | awk 'NR%3==0 {print $1}'
. For upload only, replace $1 with $2. Replace wlan0 with your interface.
EDIT: So the above works in that it extracts what you want from the ifstat output, but what ifstat reports does not seem very accurate, at least with a count of 1. Maybe it takes a few updates before it reports something accurate?
ifstat -i wlan0 1 1 | awk 'NR%3==0 {print $1/1024}'
, but a quick test shows inaccurate rates. You might play around with a larger count. Maybe something like this untested command: ifstat -i wlan0 1 3 | awk 'NR%5==0 {print $1}'
.According to ifstat(1), the rates are reported in kbytes/sec by default and with the -b flag, kbits/sec. If you wanted MB/s, you could use something likeifstat -i wlan0 1 1 | awk 'NR%3==0 {print $1/1024}'
, but a quick test shows inaccurate rates. You might play around with a larger count. Maybe something like this untested command:ifstat -i wlan0 1 3 | awk 'NR%5==0 {print $1}'
.
#!/bin/bash
while true; do
»···date="$(date "+%a %d-%m-%Y %H:%M:::%Z")"
»···volume="$(mixer | grep 'pcm' | awk '{print $7}')"
»···cputemp="$(sysctl -a | grep 'dev.cpu.5.temperature' | awk '{print $2}')"
»···memusage="$(freecolor -m -o | grep 'Mem' | awk '{print $4}')"
»···memtotal="$(freecolor -m -o | grep 'Mem' | awk '{print $2}')"
»···ipaddress="$(ifconfig re0 | grep 'inet' | awk '{print $2}')"
»···download="$(ifstat -i re0 1 3 | awk 'NR%5==0 {print $1}')"
»···upload="$(ifstat -i re0 1 3 | awk 'NR%5==0 {print $2}')"
»···xsetroot -name " ${download}KB/s ${upload}KB/s ${memusage}MB/${memtotal}MB ${cputemp} $ipaddress $volume $date "
»···sleep 1
done