Created
May 23, 2013 19:37
-
-
Save csfrancis/5638827 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Show if stats by sampling /sys/. | |
# Originally stolen from http://unix.stackexchange.com/questions/41346/upload-download-speed-in-tmux-status-line | |
run_segment() { | |
sleeptime="0.5" | |
iface="eth0" | |
RXB=$(</sys/class/net/"$iface"/statistics/rx_bytes) | |
TXB=$(</sys/class/net/"$iface"/statistics/tx_bytes) | |
sleep "$sleeptime" | |
RXBN=$(</sys/class/net/"$iface"/statistics/rx_bytes) | |
TXBN=$(</sys/class/net/"$iface"/statistics/tx_bytes) | |
RXDIF=$(echo $((RXBN - RXB)) ) | |
TXDIF=$(echo $((TXBN - TXB)) ) | |
rx=$(echo "${RXDIF} / 1024 / ${sleeptime}" | bc) | |
tx=$(echo "${TXDIF} / 1024 / ${sleeptime}" | bc) | |
echo "⇊ ${rx}K/s ⇈ ${tx}K/s" | |
return 0 | |
} | |
run_segment |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment