Remove Address List Entry by Comment

Hi there,

I have another problem I need some help with. I want to write a script which resolves a host and adds the address to an address list so that it can be used in firewall rules. Of course I need to delete the old entries first, which I want to do by comment (as some entries of the same list are static and don’t need updating). But when I try

:local comment "Auto_Update"
/ip firewall address-list remove [find comment="$comment"]

ALL my address lists get deleted (luckily I had a recent backup…).

What am I doing wrong?

Thanks and kind regards,
iBlueDragon

Use another local variable other than ‘comment’ and see if it solves it. RouterOS script engine apparently runs into problem when you try to call a variable with the same name as some other part of the argument.

Thanks Devil,

That really solved it. Didn’t think of it because I copied some of the code from another forum post where the variable was used like that…

Kind regards,
iBlueDragon

Hi friend … maybe this can serve you, it depends on you as you want to modify and use.

/ip firewall address-list remove [/ip firewall address-list find list=“list-name”]

modify (list-name) since this will remove all the names,
not this one that you do a backub before.

God bless you.

This one saved me!

Uselessly complex:

/ip firewall address-list remove [find where list="list-name"]

and the OP is “Remove Address List Entry by Comment” so:

/ip firewall address-list remove [find where comment="the comment"]

but that delete only when the comment is EXACTLY “the comment” (case sensitive)

for delete when a part of the comment is abcde (case sensitive):

/ip firewall address-list remove [find where comment~"abcde"]

but if they need to be deleted regularly, it is better to import them as dynamic, so they are not written in export and do not wearing the internal flash,
they are lost upon reboot, and they are automatically deleted after the time set to your liking.