Few notes about the "new"
Dynu script above:
1. My script above is for NEWER RouterOS versions. Specifically, it uses an ":onerror" built-in command which was added recently. Since one way to deal with potential script error is more output on what a script is going... the newer ":onerror" is needed to capture any error message from /tool/fetch so it can go to the logs/console.
2. Some of the logging use "/log/debug" which is NOT enabled by default. I do this since once it works... there is no need to clutter logs. BUT... if something does go wrong with my script, you can enabled "debug" log topic using a "/system/logging add topics=debug" to see any "/log/debug" message if run from script/scheduler. If run from the CLI, however, all logging is always shown since [:put] does not have a log level (and called before the /log).
3.
Dynu seems to have a newer REST API, that uses an "API Key". I don't use that here - since you have do stuff in your account to get the API key and different code. But using an API key and REST method be better since the user/password wouldn't have to be stored on RouterOS. And since recent RouterOS support JSON, it be possible.
On Mr. Rextended's comments...
The function would look better and be easier internally if hostname does not have to be specified as the first parameter.
I would suggest entering the parameter as host=".." which would also be specifiable in any position...
Perhaps. I just use the "subject"/"noun" of the function's operation as an "positional parameter". While things that
control a function's operation get named parameters with the user=syntax. So "myhost.ddnsgeek.com" is kinda the noun/subject, it does not an attribute in my schemes...
But really just style.... It be easy to change script to take a "host=", as the $1 is used only two spots if someone wanted to...
But where $1 is does NOT actually matter. It works before or after any "named arguments". For example,
:global anyorder do={
:put "\$1 is $1"
:put "\$arg1 is $arg1"
:put "\$arg2 is $arg2"
}
$anyorder arg1=val1 arg2=val2 unnamedArg
$1 is unnamedArg
$arg1 is val1
$arg2 is val2
$anyorder arg1=val1 unnamedArg arg2=val2
$1 is unnamedArg
$arg1 is val1
$arg2 is val2
Also is nice if RegEx (I have already posted on forum) is used for check hostname validity before submit.....
Perhaps. Just it was already a long script. And
Dynu will report the name is not associated with the account back from /tool/fetch, so not end of world. Andshould show up as some kinda of error in log/:put.
I actually did have a "[:convert from=raw to=url mydns.example.com]" in the code to deal with url-encoding... but since DNS names should NOT have anything that needs escaping I removed it. And username/password would be dealt with by /tool/fetch.