Page 1 of 1

Mikrotik API

Posted: Mon Sep 07, 2015 11:48 am
by icu4ever
Hi everyone,

i wanna run this mikrotik script
" :foreach i in=[/tool user-manager session find ] do {/tool user-manager session remove $i;} " into c# with api

i got this error
[0]: "!trap=category=0=message=no such command or directory (foreach i in=[)"
[1]: "!trap=message=no such command prefix"
[2]: "!done"

Re: Mikrotik API

Posted: Mon Sep 07, 2015 12:15 pm
by janisk
please check RouterOS API manual. You will see that you cannot run scripts via API.

Re: Mikrotik API

Posted: Tue Sep 08, 2015 12:12 am
by boen_robot
FWIW, this is a bad way to remove all sessions, even in scripting alone.

Using "find" inside the remove itself is far more compact, as well as more efficient:
/tool user-manager session remove [find]
The only time using :foreach is necessary is if your criteria can't be covered by the "where" inside the "find".

To do the above (not using :foreach) using the API, you need to execute the inner command, and pass it's results to the outer command.

So f.e.
/tool/user-manager/session/find

!done
=ret=*1,*2,*3

/tool/user-manager/session/remove
=numbers=*1,*2,*3

!done