Well sindy!
I modified the script to:
:if ($bound=1) do={
:log info “DHCP lease ready”
/system script run refreshdyndns
}
and now I get the log entry after getting the IP
May/16/2020 16:05:05 dhcp,critical,error dhcp-client on ether1 lost IP address 44.33.22.11 - received NAK from dhcp server 10.20.30.40
May/16/2020 16:05:05 dhcp,info dhcp-client on ether1 got IP address 44.33.22.11
DHCP lease ready
But the script is not running, there are no log entries.
Attached the script refreshdyndns:
DynDNS refresh
:local ddnsbase “sub01.DOMAIN.TLD”
:local hostsarray {
{“sub01.DOMAIN.TLD”;“DOMAIN.TLD-id01”;“pwd”};
{“sub02.DOMAIN.TLD”;“DOMAIN.TLD-id02”;“pwd”};
{“sub03.DOMAIN.TLD”;“DOMAIN.TLD-id03”;“pwd”};
{“sub04.DOMAIN.TLD”;“DOMAIN.TLD-id04”;“pwd”}
}
:local ddnshost
:local ddnsuser
:local ddnspass
:local theinterface “ether1”
:local msghd “DynDNS:”
:local emailaddressRT “log@DOMAIN.TLD”
:local ipddns [:resolve $ddnsbase]
:local ipfresh [/ip address get [/ip address find interface=$theinterface] address]
:if ([ :typeof $ipfresh ] = nil ) do={
:log info (“$msghd NO IP address on $theinterface”)
} else={
:set ipfresh [:pick $ipfresh 0 [:find $ipfresh “/”]]
#CHECK new<>old IP
:if ($ipddns != $ipfresh) do={
:foreach hstarr in=$hostsarray do={
:set ddnshost [($hstarr->0)]
:set ddnsuser [($hstarr->1)]
:set ddnspass [($hstarr->2)]
:log info (“$msghd $ddnshost DNSRECORDIP=$ipddns INTERFACE $theinterface CURRENTIP=$ipfresh UPDATING $ddnshost->$ipfresh”)
:local srcpath “nic/update?system=dyndns&hostname=$ddnshost&myip=$ipfresh”
/tool fetch address=www.PROVIDER.com host=www.PROVIDER.com src-path=$srcpath mode=https user=$ddnsuser password=$ddnspass dst-path=(“/DynDNS.$ddnshost”)
:delay 1
:local result [/file get “DynDNS.$ddnshost” contents]
:log info “$msghd PROVIDER response: $result”
:local firstword [:pick $result 0 5]
:if ($firstword = “good “) do={
:log info “$msghd SUCCESS”
} else={
:if ($firstword = “nochg”) do={
:log info “$msghd NOCHANGE”
/tool e-mail send to=”$emailaddressRT” subject=“$msghd FAILED IP $ipfresh” body=“an error occured”
} else={
:log info “$msghd FAILED”
}
}
:local ipddns $ipfresh
:log info “$msghd $ddnshost DNS RECORD = $ipfresh”
}
} else={
#EXIT when IP did not change
:log info “$msghd IP $ipfresh checked OK”
}
}
When IP doesnt change, script runs until position “#CHECK new<>old IP”
and finishes at position “#EXIT when IP did not change”
Have I missed something in the srcipt?