When I copy and paste this code into my terminal it works fine. However, when I type /server script run and check the logs, it freezes right after my “inside the if statement”. Something is wrong with my DNS update code, but I can’t figure out why it works when I copy and paste, but not when I run the script. What am I missing?
# ROUTER SPECIFIC VARIABLES
:global ddns-keyname "my key name"
:global ddns-keyvalue "my key"
:global ddns-fullhostname "my hostname"
# COMMON VARIABLES ACROSS ROUTERS (DON'T NEED TO BE CHANGED)
:global ddns-host [:pick $ddns-fullhostname 0 [:find $ddns-fullhostname .]
:global ddns-zone "my zone"
:global ddns-server "my dns server"
:global ddns-interface WAN1
#
# CHECK TO SEE IF THE DHCP HAS BEEN "BOUND"
:local i 0
:while ($i != 1) do={
:if ([/ip dhcp-client get $ddns-interface status] = "bound") do={
:set i 1
:log info ("i = " . $i)
};
:delay 1s
};
#AFTER DHCP HAS BEEN BOUND, FIND THE IP
:global WAN1-ip [:pick [/ip address get [/ip address find interface=$ddns-interface] address] 0 [:find [/ip address get [/ip address find interface=$ddns-interface] address] "/"]]
:log info ($WAN1-ip . " ?= " . [:resolve $ddns-fullhostname])
:if ($WAN1-ip != [:resolve $ddns-fullhostname]) do={
:log info "inside the if statement"
/tool dns-update dns-server=$ddns-server name=$ddns-host zone=$ddns-zone address=$WAN1-ip key-name=$ddns-keyname key=$ddns-keyvalue
:log info "DNS update done"
} else { :log info "wan ip and hostname already the same" }
[/code]