Remove mac address in IP-DHCP-LEASE from another script

Friends, I want to delete the mac address in IP DHCP leases by searching for that mac address in IP Hotspot Cookies.
I have this script, but it doesn’t delete it.


:local Maddress [/ip hotspot cookie get [find where user="test"] mac-address]
/ip dhcp-server lease remove $Maddress

no such item


Thank you for your valuable help.

remove where?

Remove from /ip dhcp server lease.


Thank you.

So, remove what? remove want a number (from print) or an item id… and MAC address is not one and not another.
why don’t you put the [find where …], that return the apporpriate id wanted from remove, in the script like on first line?

I’ve tried as you say.

:local Maddress [/ip hotspot cookie get [find where user="test"] mac-address]
/ip dhcp-server lease remove [find where=$Maddress]

I don’t understand anything.

why on first you do not wrote [find where=“test”] ???
the reason why it doesn’t work in the second line is the same.

you’re close… compare the two [find …] and see why the second one is not similar to the first one.

{
{… :local Maddress [/ip hotspot cookie get [find where user=“test”] mac-address]
{… :put $Maddress
{… /ip dhcp-server lease remove $Maddress
{… }
EE:03:76:97:AF:8A
no such item

Can you help me sir REXTENDED.

Let’s see if I can help.
This is not strictly Mikrotik specific, in most scripting language something like this:

[/ip hotspot cookie get [find where > user> => “test”> ] > mac-address> ]

loosely means:
in the context of current place (/ip hotspot cookie) get the value of the field mac-address of the entry where the value of field user is equal to “test”

Now, the:

/ip dhcp-server lease remove [find where=$Maddress]

can be written as:
in the context of current place (/ip dhcp-server lease) remove the entry(ies) where the value of the field “MISSING?” :open_mouth: is equal to the value of the variable $Maddress