dotfiles/scripts/status/nettraf

22 lines
748 B
Bash
Executable file

#!/bin/sh
# Modified version of Luke Smith's network usage script
# Store transferred and recieved bytes
rstart="$(($(cat /sys/class/net/[ew]*/statistics/rx_bytes | paste -sd '+')))"
tstart="$(($(cat /sys/class/net/[ew]*/statistics/tx_bytes | paste -sd '+')))"
sleep 1
rend="$(($(cat /sys/class/net/[ew]*/statistics/rx_bytes | paste -sd '+')))"
tend="$(($(cat /sys/class/net/[ew]*/statistics/tx_bytes | paste -sd '+')))"
# Format correctly and print
dow=$(printf "%2sB\n" "$(numfmt --to=iec $(($rend-$rstart)))")
up=$(printf "%2sB\n" "$(numfmt --to=iec $(($tend-$tstart)))")
dow="${dow#* }"
dow="${dow% *}"
up="${up#* }"
up="${up% *}"
datestr="$(date '+%F %R:%S')"
printf "\033[2m%s\033[0m | %-12s | %-12s\n" "$datestr" "down: $dow" "up: $up"