Stop a running background /tool fetch

I have the following setup to do load testing:

  • An array of 20 SXTs
  • One mANT
  • A server behind the mANT

On each SXT there is a script that when run, it starts 10 scheduler tasks which in turn start parallel /tool fetch commands to download (and discard) a 10 MB .zip. This works really nice, but I find that when I remove all the scheduler tasks, there are still many “leftover” fetch commands still running, and bandwidth usage stays high for 1-3 more minutes after the test is stopped.

Is there any way to stop an ongoing background download?

First of all I would suggest to use tools which are specially designed for traffic testing:

Bandwidth Test:
https://wiki.mikrotik.com/wiki/Manual:Tools/Bandwidth_Test

Traffic Generator:
https://wiki.mikrotik.com/wiki/Manual:Performance_Testing_with_Traffic_Generator

If you still want to use described method, all script jobs can be terminated with:
/system script job remove [find]

But in case if you want to terminate exactly some specific job which is executed in background, you need to store the script job ID first, and terminate the same ID later.

Quick example how to assign ID to array val, and stop it after specified period of time:

{
    :global arr { "job1"="val1" ; "job2"="val2" }

    ### Set job ID to array val
    :foreach k,v in=$arr do={
        :set ($arr->"$k") [:execute {while (true) do={/tool fetch mode=http url="http://10.5.115.30/BS/1MB.test"}} ]
    }

    :delay 5

    ### Terminate all jobs
    :foreach k,v in=$arr do={
        :put ("Terminate $k=$v")
        /system script job remove $v
    }
}

Other option would be to start multiple scirpts, and remove them by script job name

Thanks so much for this - we use Bandwidth Test for certain segments of the network, but we want to be able to test traffic under “real” conditions, passing traffic through all Mikrotik boxes in the chain. Other than having a device behind each SXT doing its own traffic (expensive!!) we chose to have the SXT do the download itself.