Page 1 of 1

script to remove old dhcp lease reservations based on last seen

Posted: Mon Jun 08, 2020 6:47 pm
by jjones
Hello everyone,

We currently use Mikrotik dhcp to hand out and automatically static leases on some of our management devices throughout the network. We do this by basically creating a trigger on lease to make it static and add some notes. This setup works great until devices are no longer needed and removed. The static lease stays there indefinitely and we have to prune though it manually every once in a while to clear up the leases. I was wondering if any script wizards out there know a simple way to prune through those based on "last seen" so we can automagically remove these monthly or weekly to free up ip addresses for new devices?

I've seen some similar ones but they were based off of hotspot and pulling the info for removal from the hotspot config which is something we do not have setup. It is simple dhcp.

Re: script to remove old dhcp lease reservations based on last seen  [SOLVED]

Posted: Mon Jun 08, 2020 7:36 pm
by pe1chl
Apparently you can select them using queries like: where last-seen>"100d"
So it should be possible to use:

/ip dhcp-server lease
remove [find last-seen>"100d"]

Re: script to remove old dhcp lease reservations based on last seen

Posted: Mon Jun 08, 2020 7:45 pm
by jjones
that'll do it! thanks!