Hi all,
Is it possible to loop through different submenus? For example I use the following commands:
/ip firewall filter reset-counters-all
/ip firewall nat reset-counters-all
/ip firewall mangle reset-counters-all
/ip firewall raw reset-counters-all
Is it possible to do something like this?
/ip firewall
:foreach table in={"filter"; "nat"; "mangle"; "raw"} do={
$table reset-counters-all
}
The above script doesn’t matter, it doesn’t even throw an error. Is it possible to change this script to work as expected or is it generally not possible to loop through submenus?
Regards,
Reto
mrz
July 27, 2020, 7:02am
2
No, you cannot use variable values as menu names or parameter/variable names.
One workaround is to use :parse
@mtz : Thanks for the advice!
Based on the hint, I came to the following solution, which is not very nice, but does the job:
:foreach table in={"filter"; "nat"; "mangle", "raw"} do={
[:parse "/ip firewall $table reset-counters-all"]
}
But there is a problem with this solution when it comes to regex:
:foreach table in={"filter"; "nat"} do={
[:parse "/ip firewall $table remove [find comment~\"vXXX$\"]"]
}
The dollar sign
$
generates an error. I tried to escape it with a backslash
\
, but it didn’t help.
Jotne
July 28, 2020, 5:10am
4
Why do you need to delete these filter/nat rules?
Post example comments.