Community discussions

MikroTik App
 
camilo17
just joined
Topic Author
Posts: 2
Joined: Wed Dec 22, 2021 5:52 am

Doing speedtest and save into variable

Tue Dec 28, 2021 6:55 am

Hello everyone,

I'm very new in mikrotik scripts, I want to do a speed test with this command:
/tool speed-test address=*.*.*.* user=$user password=$password
And save the result into a variable so I do this:
:local speedTest;
:local tcpDownload;

/log info "[LOG] begin";

:set  $speedTest  [speed-test address=*.*.*.* user=$user password=$password];
:set $tcpDownload ($speedTest->"tcp-download");

/log info "[LOG] result speedtest $tcpDownload";
but $tcpDownload is empty on my log, and if I execute the command in the terminal it works so I don't know why this doesn't work.

Thank you for your help.
 
jonah1810
Frequent Visitor
Frequent Visitor
Posts: 98
Joined: Tue Jul 30, 2019 10:19 pm

Re: Doing speedtest and save into variable

Fri Dec 31, 2021 1:53 am

I never use speed test on my mikrotik but i wrote a script that does a very similar thing with bandwidth test. Runs a tcp count 1 test for 20s then takes the 10s average. then does the same for tx. Logs rx/tx averages with Ip.
/tool {
:local rxAvg 0
:local txAvg 0
:local addr 10.100.100.172
bandwidth-test $addr duration=20s direction=receive protocol=tcp connection-count=1 user=admin  do={
:set rxAvg ($"rx-10-second-average"/1000000)
}
bandwidth-test $addr duration=20s direction=transmit protocol=tcp connection-count=1 user=admin  do={
:set txAvg ($"tx-10-second-average"/1000000)
}
:log warning message="$addr Rx/Tx: $rxAvg/$txAvg Mbps"
} 


you don't need the semicolons to end lines, only to have multiple commands on the same line. If i had to guess why yours isn't working as a script run from the mikrotik: your variables might not be in the same scope. Try putting the whole script inside a set of curly brackets.

Who is online

Users browsing this forum: diamuxin and 15 guests