1

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

  • Can someone help me? How I can create variables reading a column with awk? How I can subtract two variables? How I can be stored in a file these variables? Thank you very much – AntonioG Apr 11 '16 at 20:48
0

Hello to all the community,

In the end, I created a script that does what I want.

Surely there is a simpler solution, but this works for me.

If anyone is interested, here I leave.

#!/bin/bash

date=$(date --iso-8601=seconds)
printf 'TIME (s)\tSIGNAL STRENGTH (dBm)\t\tTxBITRATE (MBit/s)\t\tRxBITRATE (MBit/s)\t\tRxRATE (KB/s)\t\tTxRATE (KB/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", t, s, txb, texttx, rxb, textrx}' >>"$date"

rx1= grep "wlan0" /proc/net/dev | awk '$1=="wlan0:"{print "1: -" $2}' > "salida1"
tx1= grep "wlan0" /proc/net/dev | awk '$1=="wlan0:"{print "1: -" $10}' > "salida2"
    sleep 1

rx2= grep "wlan0" /proc/net/dev | awk '$1=="wlan0:"{print "2: "$2}' >> "salida1"
tx2= grep "wlan0" /proc/net/dev | awk '$1=="wlan0:"{print "2: "$10}' >> "salida2"

awk '{ sum += $2/1000 } END { printf "\t\t\t"sum}' salida1 >> "$date"
sum=0; 
awk '{ sum += $2/1000 } END { print "\t\t\t"sum}' salida2 >> "$date" 
sum=0;

done

Greetings,

AntonioG.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.