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.
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.