0

I have file contains results of my speed test that has run in past few hours through my script. The results in the text file is follows, Script started on Monday 23 July 2018 04:41:11 PM IST file name is speedtest.txt Script started on Monday 23 July 2018 04:41:11 PM IST

root@xxxx: root@xxxx:~# 
root@xxxx: root@xxxx:~# speedtest-cli --simple
Ping: 40.629 ms
Download: 19.67 Mbit/s
Upload: 1.08 Mbit/s
root@xxxx: root@xxxx:~# speedtest-cli --simple
Ping: 51.229 ms
Download: 22.16 Mbit/s
Upload: 0.80 Mbit/s
root@xxxx: root@xxxx:~# speedtest-cli --simple
Ping: 50.924 ms
Download: 21.82 Mbit/s
Upload: 1.07 Mbit/s
root@xxxx: root@xxxx:~# speedtest-cli --simple
Ping: 51.438 ms
Download: 20.87 Mbit/s
Upload: 0.67 Mbit/s
root@xxxx: root@xxxx:~# speedtest-cli --simple
Ping: 51.149 ms
Download: 21.51 Mbit/s
Upload: 0.94 Mbit/s
root@xxxx: root@xxxx:~# exit
exit

Script done on Monday 23 July 2018 04:51:11 PM IST

I am taking the Download speed alone with the following awk command,

sudo cat speedtest.txt | grep "Download:" | cut -d ' ' -f2 | awk '{ SUM += $1} END { print SUM }' | awk '{ SUM = $1/5} END {print SUM}'

Out put of the above command is,

21.206

Now I want to verify the above value is greater than my assured value or not. I tried to save this value in a separate runTime variable and compare it with my static value let say 21.206 >= 25 or not. But I could no find the command working for me. It keep adding a new line after it stored in the new variable. So is there any way that I can compare the output value with awk and can show it is true or false? I am using expect script to save the file "speedtest.txt

1 Answer 1

3

The whole command pipe could be reduced to:

$ cat speedtest.txt | awk '/Download:/{sum+=$2}END{print sum/5}'
21.206

Or even better, avoiding the "useless use of cat":

$ awk '/Download:/{sum+=$2}END{print sum/5}' speedtest.txt
21.206

To be able to read more than 5 measurements, use:

$ awk '/Download:/{s+=$2;c++}END{print( s/c ) }' speedtest.txt

And, to get a TRUE/FALSE string use:

$ awk '/Download:/{s+=$2;c++}END{print(s/=c,s>25?"TRUE":"FALSE")}' speedtest.txt
21.206 FALSE
0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.