dotfiles/.local/scripts/status/0010_1_network

72 lines
1.7 KiB
Plaintext
Raw Normal View History

2022-08-14 05:37:27 +08:00
#!/bin/bash
DEVICE=wlan0
2022-08-16 18:50:49 +08:00
COLOR1="#FF9B00"
COLOR2="#A16200"
2022-08-14 05:37:27 +08:00
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
2022-08-19 18:02:28 +08:00
echo "Change DEVICE in ~/.local/scripts/0010_1_network"
2022-08-14 05:37:27 +08:00
grep ":" /proc/net/dev | awk -F: '{print $1}' | sed s@\ @@g
exit 1
fi
2022-08-19 18:02:28 +08:00
if [ ! -f $HOME/.local/tmp/.tmp_RXNET_BIT ]
2022-08-14 05:37:27 +08:00
then
RXNET_BIT=0
TXNET_BIT=0
2022-08-19 18:02:28 +08:00
echo $RXNET_BIT > $HOME/.local/tmp/.tmp_RXNET_BIT
echo $TXNET_BIT > $HOME/.local/tmp/.tmp_TXNET_BIT
2022-08-14 05:37:27 +08:00
fi
2022-08-19 18:02:28 +08:00
RXNET_BIT=$(cat $HOME/.local/tmp/.tmp_RXNET_BIT)
TXNET_BIT=$(cat $HOME/.local/tmp/.tmp_TXNET_BIT)
2022-08-14 05:37:27 +08:00
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}'`
2022-08-19 18:02:28 +08:00
echo $RXNET_BIT > $HOME/.local/tmp/.tmp_RXNET_BIT
echo $TXNET_BIT > $HOME/.local/tmp/.tmp_TXNET_BIT
2022-08-14 05:37:27 +08:00
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
2022-08-14 05:39:07 +08:00
outb=$(printf "%.2f KB/s" $(echo "scale=2; $outbound / 1024" | bc))
2022-08-14 05:37:27 +08:00
else
outb=$(printf "%i B/s" $outbound)
fi
2022-08-16 18:50:49 +08:00
echo "^c$COLOR1^^b$COLOR2^ In: $inb ^b$COLOR1^^c$COLOR2^  ^c$COLOR1^^b$COLOR2^ Out: $outb ^d^"