Thanks for the tips!
I'm still having trouble though.
So, here is what I did:
I first deleted the global variable currentIP to make sure that the script would run. Then, in a terminal, I ran this:
[adminROUTER] > [
[... :global currentIP;
[... :put $currentIP;
[... :local newIP [/ip address get [find interface="pppoe-bell1"] address];
[... :put $newIP
[... :if ($newIP != $currentIP) \
[\... do={ \
[{\... :put "ip address $currentIP changed to $newIP"; \
[{\... :put "Running script"; \
[{\... :set currentIP $newIP; \
[{\... }
[... ]
1.2.3.4/32
ip address changed to 1.2.3.4/32
Running script
So, everything is fine, the first line is empty because the variable doesn't exist yet. After that:
[admin@ROUTER] > /environment print
currentIP="1.2.3.4/32"
Again, everything's good. Let's run it again with the variable present:
[admin@ROUTER] > [
[... :global currentIP;
[... :put $currentIP;
[... :local newIP [/ip address get [find interface="pppoe-bell1"] address];
[... :put $newIP
[... :if ($newIP != $currentIP) \
[\... do={ \
[{\... :put "ip address $currentIP changed to $newIP"; \
[{\... :put "Running script"; \
[{\... :set currentIP $newIP; \
[{\... }
[... ]
1.2.3.4/32
1.2.3.4/32
So, basically, everything works in terminal. I deleted the currentIP variable and re-enabled the scheduler to see if it worked, and again, I was getting those log message "ip address changed to 1.2.3.4/32" everytime the scheduler ran.
I deleted the variable again and changed my script to this to try to determine where the problem is:
:global currentIP;
:log info "$currentIP";
:local newIP [/ip address get [find interface="pppoe-bell1"] address];
:log info "$newIP";
:if ($newIP != $currentIP) \
do={ \
:log info "ip address $currentIP changed to $newIP"; \
/system script run ddns-update; \
:set currentIP $newIP; \
}
The result is three lines (and repeating) in my logs:
First line with nothing, this is where the currentIP should be. It is ok to be empty on first run after deleting the variable.
Second line: 1.2.3.4/32
Third line: ip address changed to 1.2.3.4/32
So, there is a probleme somewhere with my global variable. Looks like the scheduler can't update my globel variable currentIP.
Ok, so, while I was writing this long post, I discovered that at some point, the script actually managed to update the currentIP variable, after like 10 tries. So, I reduced the timer and tried again. Same result, but after like 15 tries it managed to update the variable. This is getting weird. So, to stop flooding afraid.org with ddns update, I removed the /system script line just to get the log message. And now, it works flawlessly (execpt for the fact that my ddns doesn't get updated)! So, I'm guessing that there is something wrong with my ddns-update script that make the scheduler do weird things. Like the script fail and return something that the scheduler can't digest. I'll try to get it to log something to see what happens. I'll get back to you when I got some result!
Thank you!