diff --git a/modules/module_net b/modules/module_net index 3610bae..052942f 100755 --- a/modules/module_net +++ b/modules/module_net @@ -4,21 +4,25 @@ # load config module_config [ -e "$HOME/.config/speedwm/statusrc" ] && . $HOME/.config/speedwm/statusrc +[ -z "$URL" ] && URL="1.1.1.1" [ "$ENABLE_ITEM6" = "true" ] || exit # get stats GETNSTAT() { - R1="$(cat /sys/class/net/[ew]*/statistics/rx_bytes || exit)" - T1="$(cat /sys/class/net/[ew]*/statistics/tx_bytes || exit)" + ip link | grep -q "UP mode" || exit + R1="$(head -n 1 /sys/class/net/[ew]*/statistics/rx_bytes)" + T1="$(head -n 1 /sys/class/net/[ew]*/statistics/tx_bytes)" sleep 0.1 - R2="$(cat /sys/class/net/[ew]*/statistics/rx_bytes || exit)" - T2="$(cat /sys/class/net/[ew]*/statistics/tx_bytes || exit)" - TXPMS="$(expr $T2 - $T1)" - RXPMS="$(expr $R2 - $R1)" - TX="$(expr $TXPMS / 1024 "*" 10)" - RX="$(expr $RXPMS / 1024 "*" 10)" - [ ! -z "$TX" ] && printf "$TX\n" > /tmp/module_net_tx - [ ! -z "$RX" ] && printf "$RX\n" > /tmp/module_net_rx + R2="$(head -n 1 /sys/class/net/[ew]*/statistics/rx_bytes)" + T2="$(head -n 1 /sys/class/net/[ew]*/statistics/tx_bytes)" + TXPMS="$(("$T2" "-" "$T1"))" + RXPMS="$(expr "$R2" "-" "$R1")" + TX="$(expr "$TXPMS" / "1024" "*" "10")" + RX="$(expr "$RXPMS" / "1024" "*" "10")" + [ ! -z "$TX" ] && printf "$TX\n" > /tmp/module_net_tx || exit + [ ! -z "$RX" ] && printf "$RX\n" > /tmp/module_net_rx || exit + [ -e "/tmp/module_net_tx" ] || exit + [ -e "/tmp/module_net_rx" ] || exit } [ ! -e "/tmp/module_net_tx" ] && GETNSTAT