read in previous data

This commit is contained in:
Luke Smith 2020-05-30 17:50:37 -04:00
parent 52d9140820
commit bb8495f27d
No known key found for this signature in database
GPG key ID: 4C50B54A911F6252

View file

@ -11,13 +11,11 @@ case "$BLOCK_BUTTON" in
esac esac
logfile="${XDG_CACHE_HOME:-$HOME/.cache}/netlog" logfile="${XDG_CACHE_HOME:-$HOME/.cache}/netlog"
prevdata="$(cat "$logfile")" || echo "0 0" > "$logfile" read -r rxprev txprev < "$logfile"
rxcurrent="$(($(paste -d '+' /sys/class/net/[ew]*/statistics/rx_bytes)))" rxcurrent="$(($(paste -d '+' /sys/class/net/[ew]*/statistics/rx_bytes)))"
txcurrent="$(($(paste -d '+' /sys/class/net/[ew]*/statistics/tx_bytes)))" txcurrent="$(($(paste -d '+' /sys/class/net/[ew]*/statistics/tx_bytes)))"
printf "🔻%sKiB 🔺%sKiB\\n" \ printf "🔻%sKiB 🔺%sKiB\\n" "$(((rxcurrent-rxprev)/1024))" "$(((txcurrent-txprev)/1024))"
"$(((rxcurrent-${prevdata%% *})/1024))" \
"$(((txcurrent-${prevdata##* })/1024))"
echo "$rxcurrent $txcurrent" > "$logfile" echo "$rxcurrent $txcurrent" > "$logfile"