Skip to content

Mikrotik exports cut off by scripts in the config #53

Description

@miken32

Exports from my device are getting cut off after certain system scripts. It seems to be something to do with the contents of the script; if I install the following script on my router, it and everything in the configuration afterwards is removed:

:local domains [:toarray ""]
:local dnsttl "90m"

:local magiccomment "automatic-from-dhcp (magic comment)"
:local activehosts [:toarray ""]

:foreach lease in [/ip dhcp-server lease find] do={
  :local hostname [/ip dhcp-server lease get value-name=host-name $lease]
  :local hostaddr [/ip dhcp-server lease get value-name=address $lease]

  :if ([:len $hostname] > 0) do={
    :foreach domain in $domains do={
      :local regdomain "$hostname.$domain"
      :set activehosts ($activehosts, $regdomain)

      :if ([:len [/ip dns static find where name=$regdomain]] = 0) do={
        # add new entry
        /ip dns static add name=$regdomain address=$hostaddr comment=$magiccomment ttl=$dnsttl
      } else={
        :if ([:len [/ip dns static find where name=$regdomain address=$hostaddr comment=$magiccomment]] = 0) do={
          # update entry only if IP, name, and comment don't match
          /ip dns static set address=$hostaddr [/ip dns static find name=$regdomain comment=$magiccomment]
        }
      }
    }
  }
}

# remove old entries
:foreach dnsentry in [/ip dns static find where comment=$magiccomment] do={
  :local hostname [/ip dns static get value-name=name $dnsentry]
  :if ([:type [:find $activehosts $hostname]] = "nil") do={
    /ip dns static remove $dnsentry
  }
}

The debug output is a little overwhelming considering my configuration is 600 lines long and each line seems to generate a half dozen lines of debug. How can I narrow down what the problem might be?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions