dotfiles/.local/scripts/status/0010_1_network

72 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
DEVICE=wlan0
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 "Change DEVICE in ~/.local/scripts/0010_1_network"
grep ":" /proc/net/dev | awk -F: '{print $1}' | sed s@\ @@g
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
if [ $inbound -gt $((1024*1024)) ]
then
inb=$(printf "%.2f MB/s" $(echo "scale=2; $inbound / 1024 / 1024" | bc))
elif [ $inbound -gt 1024 ]
then
inb=$(printf "%.2f KB/s" $(echo "scale=2; $inbound / 1024" | bc))
else
inb=$(printf "%i B/s" $inbound)
fi
if [ $outbound -gt $((1024*1024)) ]
then
outb=$(printf "%.2f MB/s" $(echo "scale=2; $outbound / 1024 / 1024" | bc))
elif [ $outbound -gt 1024 ]
then
outb=$(printf "%.2f KB/s" $(echo "scale=2; $outbound / 1024" | bc))
else
outb=$(printf "%i B/s" $outbound)
fi
echo "^c$COLOR1^^b$COLOR2^ In: $inb ^b$COLOR1^^c$COLOR2^  ^c$COLOR1^^b$COLOR2^ Out: $outb ^d^"