Community discussions

MikroTik App
 
jjones
just joined
Topic Author
Posts: 20
Joined: Wed Mar 06, 2013 11:42 pm

script to remove old dhcp lease reservations based on last seen

Mon Jun 08, 2020 6:47 pm

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.
 
pe1chl
Forum Guru
Forum Guru
Posts: 7185
Joined: Mon Jun 08, 2015 12:09 pm

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

Mon Jun 08, 2020 7:36 pm

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"]
 
jjones
just joined
Topic Author
Posts: 20
Joined: Wed Mar 06, 2013 11:42 pm

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

Mon Jun 08, 2020 7:45 pm

that'll do it! thanks!

Who is online

Users browsing this forum: No registered users and 10 guests