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

20 lines
437 B
Plaintext
Raw Normal View History

2022-07-04 21:36:33 +02:00
#!/bin/sh
2023-02-21 17:49:55 +01:00
2023-04-12 11:37:10 +02:00
big="\e[11m"
reset="\e[10m"
2023-02-21 17:49:55 +01:00
2022-07-04 21:36:33 +02:00
update() {
2023-02-07 17:19:53 +01:00
sum=0
for arg; do
read -r i <"$arg"
sum=$((sum + i))
done
cache=/tmp/${1##*/}
[ -f "$cache" ] && read -r old <"$cache" || old=0
printf %d\\n "$sum" >"$cache"
printf %d\\n $((sum - old))
2022-07-04 21:36:33 +02:00
}
rx=$(update /sys/class/net/[ew]*/statistics/rx_bytes)
tx=$(update /sys/class/net/[ew]*/statistics/tx_bytes)
2023-04-12 11:37:10 +02:00
printf "$big$reset%5sB $big$reset%5sB\\n" $(numfmt --to=iec "$rx" "$tx")