1
0
Fork 0
dotfiles/.local/bin/statusbar/sb-nettraf

16 lines
423 B
Plaintext
Raw Normal View History

2022-07-04 21:36:33 +02:00
#!/bin/sh
update() {
sum=0
for arg; do
read -r i < "$arg"
sum=$(( sum + i ))
done
2022-08-07 12:54:35 +02:00
cache=/tmp/${1##*/}
2022-07-04 21:36:33 +02:00
[ -f "$cache" ] && read -r old < "$cache" || old=0
printf %d\\n "$sum" > "$cache"
printf %d\\n $(( sum - old ))
}
rx=$(update /sys/class/net/[ew]*/statistics/rx_bytes)
tx=$(update /sys/class/net/[ew]*/statistics/tx_bytes)
2022-08-22 20:33:37 +02:00
printf "%5sB %5sB\\n" $(numfmt --to=iec $rx $tx)