Community discussions

MikroTik App
 
bbahes
newbie
Topic Author
Posts: 31
Joined: Fri May 20, 2016 11:44 am

Enable multiple firewall rules based on find in script

Wed Jun 22, 2022 8:41 pm

Hi,

I'm trying to enable/disable multiple firewall rules based on find result.

I switched from:
/ip/firewall/filter/enable numbers=6,7

to:
/ip/firewall/filter/enable numbers=[find comment="ddns_1"];
/ip/firewall/filter/enable numbers=[find comment="ddns_2"];

Is it possible to combine two lines with find part to single?

Thanks.
 
pe1chl
Forum Guru
Forum Guru
Posts: 10529
Joined: Mon Jun 08, 2015 12:09 pm

Re: Enable multiple firewall rules based on find in script  [SOLVED]

Wed Jun 22, 2022 8:57 pm

That depends on what other comments you have in your firewall rules.
When there are no other comments with ddns in them you can use: [find comment~"ddns_"]
But of course that will fail when there is also a ddns_3 or extra_ddns_2 or something like that.
 
bbahes
newbie
Topic Author
Posts: 31
Joined: Fri May 20, 2016 11:44 am

Re: Enable multiple firewall rules based on find in script

Wed Jun 22, 2022 9:20 pm

That depends on what other comments you have in your firewall rules.
When there are no other comments with ddns in them you can use: [find comment~"ddns_"]
But of course that will fail when there is also a ddns_3 or extra_ddns_2 or something like that.
This works fine.
I have only two rules with comments ddns_1 and ddns_2. I have tested with additional ddns_3 and it also works.
Now I see that there is good reference in https://help.mikrotik.com/docs/display/ROS/Scripting which I'll check also.

Thanks for quick response.
 
pe1chl
Forum Guru
Forum Guru
Posts: 10529
Joined: Mon Jun 08, 2015 12:09 pm

Re: Enable multiple firewall rules based on find in script

Wed Jun 22, 2022 10:13 pm

Of course with "fail" I meant that "if ddns_3 exists it will enable that as well" while maybe you wanted only to enable ddns_1 and ddns_2.
So it depends on what you want if the solution works.
It is possible to make it match only ddns_1 and ddns_2 but that would make it more complicated, like "^ddns_[12]"

Who is online

Users browsing this forum: No registered users and 20 guests