minimize file writes and use built-in arithmatic
This commit is contained in:
parent
406bb4faa7
commit
1379747a17
1 changed files with 7 additions and 9 deletions
|
@ -10,16 +10,14 @@ case "$BLOCK_BUTTON" in
|
||||||
6) "$TERMINAL" -e "$EDITOR" "$0" ;;
|
6) "$TERMINAL" -e "$EDITOR" "$0" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
rxfile="${XDG_CACHE_HOME:-$HOME/.cache}/rxlog"
|
logfile="${XDG_CACHE_HOME:-$HOME/.cache}/netlog"
|
||||||
txfile="${XDG_CACHE_HOME:-$HOME/.cache}/txlog"
|
prevdata="$(cat "$logfile")"
|
||||||
|
|
||||||
rxcurrent="$(cat /sys/class/net/*/statistics/rx_bytes | paste -sd '+' | bc)"
|
rxcurrent="$(($(cat /sys/class/net/*/statistics/rx_bytes | paste -sd '+')))"
|
||||||
txcurrent="$(cat /sys/class/net/*/statistics/tx_bytes | paste -sd '+' | bc)"
|
txcurrent="$(($(cat /sys/class/net/*/statistics/tx_bytes | paste -sd '+')))"
|
||||||
|
|
||||||
printf "🔻%sKiB 🔺%sKiB\\n" \
|
printf "🔻%sKiB 🔺%sKiB\\n" \
|
||||||
"$(printf -- "(%s-%s)/1024\\n" "$rxcurrent" "$(cat "$rxfile")" | bc)" \
|
"$(((rxcurrent-${prevdata%% *})/1024))" \
|
||||||
"$(printf -- "(%s-%s)/1024\\n" "$txcurrent" "$(cat "$txfile")" | bc)"
|
"$(((txcurrent-${prevdata##* })/1024))"
|
||||||
|
|
||||||
# Log the current values for next run.
|
echo "$rxcurrent $txcurrent" > "$logfile"
|
||||||
echo "$rxcurrent" > "$rxfile"
|
|
||||||
echo "$txcurrent" > "$txfile"
|
|
||||||
|
|
Loading…
Reference in a new issue