From d5afb7822f68c8f4204db491f3c9f27d87d3bcd3 Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Sat, 10 Apr 2021 00:35:06 -0300 Subject: [PATCH] gets the RX and TX values and transform to kB/s --- scripts/network_bandwith.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 scripts/network_bandwith.sh diff --git a/scripts/network_bandwith.sh b/scripts/network_bandwith.sh new file mode 100755 index 0000000..682a0cc --- /dev/null +++ b/scripts/network_bandwith.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +INTERVAL="1" # update interval in seconds + +network_name=$(tmux show-option -gqv "@dracula-network-bandwith") + +main() { + while true + do + initial_download=`cat /sys/class/net/$network_name/statistics/rx_bytes` + initial_upload=`cat /sys/class/net/$network_name/statistics/tx_bytes` + + sleep $INTERVAL + + final_download=`cat /sys/class/net/$network_name/statistics/rx_bytes` + final_upload=`cat /sys/class/net/$network_name/statistics/tx_bytes` + + total_download_bps=`expr $final_download - $initial_download` + total_upload_bps=`expr $final_upload - $initial_upload` + + total_download_kbps=$(echo "scale=2; $total_download_bps / 1024" | bc) + total_upload_kbps=$(echo "scale=2; $total_upload_bps / 1024" | bc) + + echo "↑ $total_upload_kbps kB/s • ↓ $total_download_kbps kB/s" + done +} +main