dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

dwmblock-nettraf (825B)


      1 #!/bin/sh
      2 
      3 # Module showing network traffic. Shows how much data has been received (RX) or
      4 # transmitted (TX) since the previous time this script ran. So if run every
      5 # second, gives network traffic per second.
      6 
      7 case $BUTTON in
      8 	1) setsid -f "$TERMINAL" -e bmon ;;
      9 	3) notify-send "🌐 Network traffic module" "🔻: Traffic received
     10 🔺: Traffic transmitted" ;;
     11 	6) "$TERMINAL" -e "$EDITOR" "$0" ;;
     12 esac
     13 
     14 update() {
     15     sum=0
     16     for arg; do
     17         read -r i < "$arg"
     18         sum=$(( sum + i ))
     19     done
     20     cache=/tmp/${1##*/}
     21     [ -f "$cache" ] && read -r old < "$cache" || old=0
     22     printf %d\\n "$sum" > "$cache"
     23     printf %d\\n $(( sum - old ))
     24 }
     25 
     26 rx=$(update /sys/class/net/[ew]*/statistics/rx_bytes)
     27 tx=$(update /sys/class/net/[ew]*/statistics/tx_bytes)
     28 
     29 printf "🔻%4sB 🔺%4sB\\n" $(numfmt --to=iec $rx $tx)