And here are the lines of my updated script, which checks to see if there already exists a static DNS entry with the correct IP address for each active DHCP lease. This avoids the log filling up (and the static RAM being unnecessarily re-written) with static DNS entries being set for DHCP leases which this script had already added on previous runs.
Thank you for the hint in an earlier comment about how to do this.
> # For DHCP leases with something/anything in the hostname, and an active IP address ...
> :if (([:len $hostname] > 0) and ([:len $hostaddr] > 0)) do={
> :foreach domain in $domains do={
> :local regdomain "$hostname.$domain"
> :set activehosts ($activehosts, $regdomain)
>
> # Only if a DNS entry does not already exist
> :if ([:len [/ip dns static find where name=$regdomain]] = 0) do={
> /ip dns static add name=$regdomain address=$hostaddr comment=$magiccomment ttl=$dnsttl
> } else={
> # But if a DNS entry did already exist, check if its IP address needs to change
> :local statichostnumber [/ip dns static find where name=$regdomain]
> :local hostoldaddr [/ip dns static get $statichostnumber address]
> :if ($hostaddr != $hostoldaddr) do={
> /ip dns static set address=$hostaddr [/ip dns static find name=$regdomain comment=$magiccomment]
> }
> }
> }
> }
>}
Jay Libove