From bb8495f27d56705d7ac55bd38c52cc605734cdb6 Mon Sep 17 00:00:00 2001 From: Luke Smith Date: Sat, 30 May 2020 17:50:37 -0400 Subject: [PATCH] read in previous data --- .local/bin/statusbar/nettraf | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.local/bin/statusbar/nettraf b/.local/bin/statusbar/nettraf index d9c2d8c..cca69aa 100755 --- a/.local/bin/statusbar/nettraf +++ b/.local/bin/statusbar/nettraf @@ -11,13 +11,11 @@ case "$BLOCK_BUTTON" in esac 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)))" txcurrent="$(($(paste -d '+' /sys/class/net/[ew]*/statistics/tx_bytes)))" -printf "🔻%sKiB 🔺%sKiB\\n" \ - "$(((rxcurrent-${prevdata%% *})/1024))" \ - "$(((txcurrent-${prevdata##* })/1024))" +printf "🔻%sKiB 🔺%sKiB\\n" "$(((rxcurrent-rxprev)/1024))" "$(((txcurrent-txprev)/1024))" echo "$rxcurrent $txcurrent" > "$logfile"