dotfiles/.local/scripts/status/0010_1_network

54 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
DEVICE=wlp2s0
COLOR1="#FF9B00"
COLOR2="#A16200"
good=0
for gooddev in `grep \: /proc/net/dev | awk -F: '{print $1}'`
do
if [ "$DEVICE" = $gooddev ]
then
good=1
break
fi
done
if [ $good -eq 0 ]
then
echo "0010"
exit 1
fi
if [ ! -f $HOME/.local/tmp/.tmp_RXNET_BIT ]
then
RXNET_BIT=0
TXNET_BIT=0
echo $RXNET_BIT > $HOME/.local/tmp/.tmp_RXNET_BIT
echo $TXNET_BIT > $HOME/.local/tmp/.tmp_TXNET_BIT
fi
RXNET_BIT=$(cat $HOME/.local/tmp/.tmp_RXNET_BIT)
TXNET_BIT=$(cat $HOME/.local/tmp/.tmp_TXNET_BIT)
line=`grep $DEVICE /proc/net/dev | sed s/.*://`
rx=`echo $line | awk '{print $1}'`
tx=`echo $line | awk '{print $9}'`
inbound=$(($rx-$RXNET_BIT))
outbound=$(($tx-$TXNET_BIT))
line=`grep $DEVICE /proc/net/dev | sed s/.*://`
RXNET_BIT=`echo $line | awk '{print $1}'`
TXNET_BIT=`echo $line | awk '{print $9}'`
echo $RXNET_BIT > $HOME/.local/tmp/.tmp_RXNET_BIT
echo $TXNET_BIT > $HOME/.local/tmp/.tmp_TXNET_BIT
inb=$(printf "%.0f MB/s" $(echo "scale=2; $inbound / 1024 / 1024" | bc))
outb=$(printf "%.0f MB/s" $(echo "scale=2; $outbound / 1024 / 1024" | bc))
echo "^c$COLOR1^^b$COLOR2^ $inb ^b$COLOR1^^c$COLOR2^  ^c$COLOR1^^b$COLOR2^ $outb ^d^"