disabling rules by comment beginnings

hi!

I would like to disable all rules where comment begins (!) with some string, like:


81 ;;; preport-name1
src-address=abcd/32:5038 protocol=tcp action=nat to-src-address=abcd

82 ;;; preport-name2
src-address=abcd/32:5039 protocol=udp action=nat to-src-address=abcd

83 ;;; preport-name3
src-address=abcd/32:5040 protocol=tcp action=nat to-src-address=abcd

84 ;;; preport-name4
src-address=abcd/32:5041 protocol=udp action=nat to-src-address=abcd

85 ;;; preport-name5
src-address=abcd/32:5042 protocol=tcp action=nat to-src-address=abcd


do not mind ABCD in src-address and to-src-address, I deleted original numbers. Those rules are correct and work.



I would like to enable and disable those rules at specific times. As you can see, I have several tens of other src-nat rules, so I want to disable and enable ONLY those which comment begins with

preport-


Is is possible somehow? I’m very weak at scripting…

thnx!

/ip firewall src-nat {:for i from 1 to 5 do [disable [find comment=("preport-name" . $i)]]}

Edgars

edgars, thank you for hint, but problem is that “name1” “name2” are used with actual nicknames, so:

preport-blabla
preport-uhuhu
preport-mehehe
preport-bububu
preport-hohoho


etc. Thus, I can’t use your script. That’s why I was asking for “beginning with”.

thnx, mp3turbo.

:foreach name in=john,jane,billy,bob,thornton,bong,smokey do={ / ip firewall src-nat disable ( "preport-" . $name ) }

RouterOS does not do string handling well (much to my dismay) meaning you kind of have to design around that (which we all hate). If you had designed the comments to be like “preport,billy” instead you could do:

:foreach rule in=[ / ip firewall src-nat find ] do={ :foreach name in=[ / ip firewall src-nat get $rule comment ] do={  :if ( $name = "preport" ) do={ / ip firewall src-nat disable $rule } } }

maybe “:pick” command would be of a help here (available in version 2.9 only)?