dotfiles/.local/scripts/9993_network

71 lines
1.6 KiB
Plaintext
Raw Normal View History

2022-08-14 05:37:27 +08:00
#!/bin/bash
DEVICE=wlan0
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/9993_network"
grep ":" /proc/net/dev | awk -F: '{print $1}' | sed s@\ @@g
exit 1
fi
if [ ! -f $HOME/.local/.tmp_RXNET_BIT ]
then
RXNET_BIT=0
TXNET_BIT=0
echo $RXNET_BIT > $HOME/.local/.tmp_RXNET_BIT
echo $TXNET_BIT > $HOME/.local/.tmp_TXNET_BIT
fi
RXNET_BIT=$(cat $HOME/.local/.tmp_RXNET_BIT)
TXNET_BIT=$(cat $HOME/.local/.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))
LASTNETTIME_BIT=$(date +%s)
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_RXNET_BIT
echo $TXNET_BIT > $HOME/.local/.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
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
echo "In: $inb  Out: $outb"