Skip to content

Instantly share code, notes, and snippets.

@csfrancis
Created May 23, 2013 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csfrancis/5638827 to your computer and use it in GitHub Desktop.
Save csfrancis/5638827 to your computer and use it in GitHub Desktop.
#!/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