Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Use GeekTool to track network data transfer rates' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use GeekTool to track network data transfer rates
Authored by: CarlRJ on Mar 27, '09 09:30:18PM
I, too, recommend iStat menus for this and similar tasks, but if you want to go shell script/GeekTool, it's fairly easy to change the script to run only about a third as many external commands (also, not everyone has /usr/sbin on their path):

#!/bin/sh

INTF=en1

# get the current number of bytes in and bytes out
sample1=(`/usr/sbin/netstat -ib | awk "/$INTF/"'{print $7" "$10; exit}'`)

# wait one second
sleep 1

# get the number of bytes in and out one second later
sample2=(`/usr/sbin/netstat -ib | awk "/$INTF/"'{print $7" "$10; exit}'`)

# find the difference between bytes in and out during that one second
# and convert bytes to kilobytes
results=(`echo "2k ${sample2[0]} ${sample1[0]} - 1024 / p" \
		  "${sample2[1]} ${sample1[1]} - 1024 / p" | dc`)

# print the results
printf "in: %.2f Kb/sec\nout: %.2f Kb/sec\n" ${results[0]} ${results[1]}


[ Reply to This | # ]
Use GeekTool to track network data transfer rates
Authored by: mael on Aug 22, '09 02:06:51PM

Hi,

does anybody else have a problem with the last line?
> printf "in: %.2f Kb/sec\nout: %.2f Kb/sec\n" ${results[0]} ${results[1]}
Unfortunately I'll get the following error: "printf: invalid number".

Could this have something to do with my system settings? Here in Europe we usually expect a comma instead of a decimal point? Could it be that printf expects a comma but finds a decimal point and coughs up?



[ Reply to This | # ]