Hello to all the community
Few days ago, I asked the community to help me create a script.
#!/bin/bash
date=$(date --iso-8601=seconds)
printf 'TIME (s)\tSIGNAL STRENGTH (dBm)\t\tTxBITRATE (MBit/s)\t\tRxBITRATE (MBit/s)\n' >"$date"
printf '\n' >>"$date"
for ((i=0; i<=120; i=i+1)); do
iw dev wlan0 station dump | awk -vt=$i '$1=="signal:"{s=$2} $1=="tx"{txb=$3} $1=="tx"{texttx=$5 $6 $7} $1=="rx"{rxb=$3} $1=="rx"{textrx=$5 $6 $7} END {printf "%d\t\t\t%d\t\t\t%.1f\t%s\t\t\t%.1f\t%s\n", t, s, txb, texttx, rxb, textrx}' >>"$date"
sleep 1
done
The script generates an output file whose name is the time it starts, as follows:
TIME (s) SIGNAL STRENGTH (dBm) TxBITRATE (MBit/s) RxBITRATE (MBit/s)
0 -64 135.0 MCS640MHz 108.0 MCS540MHz
1 -64 135.0 MCS640MHz 108.0 MCS540MHz
2 -66 90.0 MCS440MHz 108.0 MCS540MHz
3 -66 120.0 MCS540MHz 108.0 MCS540MHz
...
This script creates a series of columns of data, but I would add other more.
I want to add the transmission rate since the previous script gets modulation and therefore the maximum rate, but not the speed in an instant. I would like to modify the script that I have to add transmision speed in another column.
I thought about getting the number of packets that were sent reading the file /proc/net/dev
grep "wlan0" /proc/net/dev | awk '$1=="wlan0:"{print $2}'; #rx packages
grep "wlan0" /proc/net/dev | awk '$1=="wlan0:"{print $10}'; #tx packages
I do not know if there is another way to do better. (Surely yes)
Therefore, the new script should be adapted to the above to read those packages in two instants of time, subtracted and divided by the time elapsed between them and stored in the same line of the main loop in another column of the same file.
The result I want to get is as follows (more or less):
TIME (s) SIGNAL STRENGTH (dBm) TxBITRATE (MBit/s) RxBITRATE (MBit/s) TxSpeed (Mbs) RxSpeed (Mbs)
0 -64 135.0 MCS640MHz 108.0 MCS540MHz 1.2 0.3
1 -64 135.0 MCS640MHz 108.0 MCS540MHz 1.5 0.4
2 -66 90.0 MCS440MHz 108.0 MCS540MHz 1.5 0.5
3 -66 120.0 MCS540MHz 108.0 MCS540MHz 2.1 0.5
...
How I can change the script that I have to add WiFi speed?
Thank you very much in advance.
A greeting.
AntonioG