Hi
I’m pulling my hair out here ![]()
I am running a script to update Unotelly DNS, based on some of the dynamic DNS scripts I’ve seen around.
My problem is that global variables set in the script somehow don’t seem to persist across executions:
:global previousIPUno
:local userhash "censored"
# Change to the name of interface that gets the dynamic IP address
:local inetinterface "isp"
#------------------------------------------------------------------------------------
# No more changes need
:if ([/interface get $inetinterface value-name=running]) do={
# Get the current IP on the interface
:local currentIP [/ip address get [find interface="$inetinterface" disabled=no] address]
# Strip the net mask off the IP address
:for i from=( [:len $currentIP] - 1) to=0 do={
:if ( [:pick $currentIP $i] = "/") do={
:set currentIP [:pick $currentIP 0 $i]
}
}
:if ($currentIP != $previousIPUno) do={
:log info "Unotelly: Current IP $currentIP is not equal to previous IP $previousIPUno, update needed"
:set previousIPUno $currentIP
# The update URL. Note the "\3F" is hex for question mark (?). Required since ? is a special character in commands.
:local url "http://api.unotelly.com/api/v1/network/update_by_hash_api\3Fuser_hash=$userhash"
:log info "Unotelly: Sending update"
/tool fetch url=($url)
:log info "Unotelly: Updated with IP $currentIP"
}
} else={
:log info "Unotelly: Previous IP $previousIPUno is equal to current IP, no update needed"
}
} else={
:log info "Unotelly: $inetinterface is not currently running, so therefore will not update."
}
:log info [/system script environment print]
The script runs from the scheduler:
20:21:03 script,info Unotelly: Current IP 105.233.57.218 is not equal to previous IP , update needed
20:21:03 script,info Unotelly: Sending update
20:21:04 info fetch: file “update_by_hash_api?user_hash=” downloaded
20:21:04 script,info Unotelly: Updated with IP 105.233.57.218
20:22:03 script,info Unotelly: Current IP 105.233.57.218 is not equal to previous IP , update needed
20:22:03 script,info Unotelly: Sending update
20:22:04 info fetch: file “update_by_hash_api?user_hash=” downloaded
20:22:04 script,info Unotelly: Updated with IP 105.233.57.218
20:23:03 script,info Unotelly: Current IP 105.233.57.218 is not equal to previous IP , update needed
20:23:03 script,info Unotelly: Sending update
20:23:04 info fetch: file “update_by_hash_api?user_hash=” downloaded
20:23:04 script,info Unotelly: Updated with IP 105.233.57.218
20:24:03 script,info Unotelly: Current IP 105.233.57.218 is not equal to previous IP , update needed
20:24:03 script,info Unotelly: Sending update
20:24:04 info fetch: file “update_by_hash_api?user_hash=” downloaded
20:24:04 script,info Unotelly: Updated with IP 105.233.57.218
20:25:03 script,info Unotelly: Current IP 105.233.57.218 is not equal to previous IP , update needed
20:25:03 script,info Unotelly: Sending update
20:25:04 info fetch: file “update_by_hash_api?user_hash=” downloaded
20:25:04 script,info Unotelly: Updated with IP 105.233.57.218
As you can see, it’s not remembering the $previousIPUno
RouterOS v6.19 on a 2011UiAS-2HnD
Any hints please?
Thanks ![]()