1

I want to test a speed connection with terminal command:

./speedtest-cli

And it returns This:

Retrieving speedtest.net configuration...
Retrieving speedtest.net server list...
Testing from Moscow, Russia (77.50.8.74)...
Selecting best server based on latency...
Hosted by East Telecom Ltd (Mytishchi) [10.81 km]: 7.433 ms
Testing download speed........................................
Download: 38.06 Mbit/s
Testing upload speed..................................................
Upload: 23.52 Mbit/s

I want to transform this to csv row like :

12-12-2016 12:01 ; 38.06 ; 23.52 ;
12-12-2016 12:11 ; 39.00 ; 21.12 ;
12-12-2016 12:21 ; 37.06 ; 25.00 ;

I'm trying to use simple grep function for this:

grep 'Upload:' test.txt | sed 's/^.*: //'  >> test_res.txt

But this is just to get speed number from file, and only rewrite one of the params. How to write exact transformation to needed format. I'm rather new in bash scripting.

  • exactly. I want to make excel table formatted file, like csv, with 3 columns. 1) date+ time 2) download speed 3) upload speed Thats it. In my examle I wrote only date, but this script would be running each 5-10 minutes, so time is important – Altenrion Jun 3 '16 at 10:51
  • edited the time stamp – Altenrion Jun 3 '16 at 10:58
1
awk  -v date="$(date +%d-%m-%Y\ %H:%M)" -v OFS=';' '/Download:/ { d=$2; }
     /Upload:/ { print date, d, $2, ""; d="" }' speedtest
  • 1) I would use it with the exact command running, like "./speedtest-cli | awk -v ....." and as i tested, it works, but can you make the date real time. I mean to place there the real date+time like in my example – Altenrion Jun 3 '16 at 11:00
  • awk -v date="$(date)" OFS=';' '/Download:/ { d=$2; } /Upload:/ { print date , d, $2, ""; d="" }' speed – malyy Jun 3 '16 at 11:09
  • ./speedtest-cli | awk -v date="$(date)" OFS=';' '/Download:/ { d=$2; } /Upload:/ { print date, d, $2, ""; d="" }' shows 1 line syntax error – Altenrion Jun 3 '16 at 11:41
  • It needs to be awk -v date="$(date)" -v OFS=';'. Note the second -v. – Michael Vehrs Jun 3 '16 at 11:54
  • Works fine. But how can I format date here to the numbers only? – Altenrion Jun 3 '16 at 12:00
0

Here is a ready solution: Download the speedtest-csv script and Give it execute permission:

wget -O speedtest-csv https://raw.githubusercontent.com/HenrikBengtsson/speedtest-cli-extras/master/bin/speedtest-csv

chmod +x speedtest-csv

Next move speedtest-csv to /usr/bin/

mv speedtest-csv /usr/bin/

Generate CSV header

speedtest-csv --header >> /var/www/html/speedtest.csv

Then, modify output for your needs, e.g. change the last line to:

echo $start ";" $upload ";" $download
or
echo $start "Upload:" $upload "Download" $download

UPDATE

I'm attaching modified script which results the following:

bash speedtest-csv
2016-06-03 14:12:21 Upload: 258.19 Mbit/s Download 242.71 Mbit/s

enter link description here

  • The script is "speedtest-cli" and writted on python. I cannot modify it, because it must be a "clean test" without rewriting this files that i obtained from speedtest server. – Altenrion Jun 3 '16 at 10:58
  • modify the output of the 'speedtest-csv' script. it's written in a bash. – malyy Jun 3 '16 at 11:00
  • I have no speedtest-csv script – Altenrion Jun 3 '16 at 11:03
  • it is shown in my post how to get it : "wget -O speedtest-csv ....." – malyy Jun 3 '16 at 11:05
  • Ok, i downloaded yours sacript, but it doesn't show the uploaad or download speed at all. Only date+ time – Altenrion Jun 3 '16 at 11:11

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.