Community discussions

MikroTik App
 
voy4g3r2
just joined
Topic Author
Posts: 13
Joined: Wed Apr 10, 2024 11:22 pm

Script Execution Error - Dynu.com 7.13 was fine 7.15 no bueno

Sat Jun 08, 2024 2:49 pm

Hello Everyone,

I use the dynu.com service and they provide update scripts for the Mikrotik Router.. which is just awesome. So I followed these steps: https://www.dynu.com/DynamicDNS/IPUpdat ... ynamic-DNS

Which worked great, on 7.13 but once I upgraded my router and access points to 7.15 I started to receive script execution errors but I have no idea why or how this is occurring.

The below screenshot
error-script-execution.png
show the errors i am getting.

Has anyone else experienced scripts that USE to work no longer work under RouterOS 7.15

Thank you in advance for any guidance.

Kind Regards,
Chris
You do not have the required permissions to view the files attached to this post.
 
User avatar
mozerd
Forum Veteran
Forum Veteran
Posts: 912
Joined: Thu Oct 05, 2017 3:39 pm
Location: Canada
Contact:

Re: Script Execution Error - Dynu.com 7.13 was fine 7.15 no bueno

Sat Jun 08, 2024 2:58 pm

Yes I do the very same as you and I get the exact same error.

When I run this script manually it works fine under all versions of 7.x up to and including 7.16beta1

But from the scheduler it’s definitely a problem starting with v7.15 and 7.16beta1
Last edited by mozerd on Sat Jun 08, 2024 7:52 pm, edited 1 time in total.
 
voy4g3r2
just joined
Topic Author
Posts: 13
Joined: Wed Apr 10, 2024 11:22 pm

Re: Script Execution Error - Dynu.com 7.13 was fine 7.15 no bueno

Sat Jun 08, 2024 3:02 pm

Yes I do the very same as you and I get the exact same error.

When I run acript this manually it works fine under all versions of 7.x up to and including 7.16beta1
Yes! same here, if run manually it works fine.. throw it in either recommended ways on website.. into a scheduled job and just does not work.
 
voy4g3r2
just joined
Topic Author
Posts: 13
Joined: Wed Apr 10, 2024 11:22 pm

Re: Script Execution Error - Dynu.com 7.13 was fine 7.15 no bueno

Sat Jun 08, 2024 4:48 pm

This issue is now resolved, it was identified there was a new-line in one of the lines, resulting in an error.

Scripting functionality is very hard to debug, does anyone have any tips they could share?
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3838
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Script Execution Error - Dynu.com 7.13 was fine 7.15 no bueno

Sat Jun 08, 2024 7:55 pm

This issue is now resolved, it was identified there was a new-line in one of the lines, resulting in an error.

Scripting functionality is very hard to debug, does anyone have any tips they could share?

You can save it as .rsc file to Files, then in CLI use ":import dnsscript.rsc verbose=yes". (And 7.16beta has more options to verbose= to help troubleshoot scripts)

That would have shown an issues issue in the first lines:
/system script
add name=Dynu
policy=read,write,test
while it should have been just "add name=Dynu policy=read,write,test". There may be other issues but lines 2-3 should have been one be the first problem.

I suspect how line-ending are treated between and/or terminal size when cut-and-pasting is involved here. RouterOS has been "doing stuff" with the line-ending in recent version, so perhaps when cut-and-pasting back line 2-3 did become just one before. Don't know. I'd imagine Dynu (or someone) tested, but the translation to webpage something went wrong & recent RouterOS has gotten picker about line-ending/etc. Anyway, a lot can go wrong in just the copy-and-paste part ;).
 
User avatar
Pulo15
just joined
Posts: 1
Joined: Sun Jun 09, 2024 11:50 am

Re: Script Execution Error - Dynu.com 7.13 was fine 7.15 no bueno

Sun Jun 09, 2024 12:01 pm

Hi guys. The same here. All scripts just stopped working after update to 7.15.
Otherwise for example this command :local cputemp [/system/health get temperature] already not working. I had to change it to :local cputemp [/system/health get [find where name=temperature] value]
 
User avatar
mozerd
Forum Veteran
Forum Veteran
Posts: 912
Joined: Thu Oct 05, 2017 3:39 pm
Location: Canada
Contact:

Re: Script Execution Error - Dynu.com 7.13 was fine 7.15 no bueno

Sun Jun 09, 2024 5:28 pm

I have checked all my scripts that are launched from scheduler and each return
No syntax errors found in the import file
IMO RoS 7.15 and 7.16beta1 the Tik scheduler has a bug and is the issue ...

If you want to check your scripts and as Amm0 suggests ... once you create a .rsc file and store it in filer

In terminal issue the following
:import file-name=yourscript.rsc verbose=progress dry-run
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3838
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Script Execution Error - Dynu.com 7.13 was fine 7.15 no bueno

Sun Jun 09, 2024 7:28 pm

Fair enough. I didn't get past the first line.

As I look beyond the 3rd line ;). The policy is right.

My guess is the "src-path=" in the /tool/fetch line. While that has historically work with HTTP, in V7 using url= is better plan.
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3838
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Script Execution Error - Dynu.com 7.13 was fine 7.15 no bueno

Mon Jun 10, 2024 12:49 am

I wrote a more modern version using a function. This works in 7.16beta1 and 7.13. Since it's a function, the parameters like username, password, WAN interface, and DDNS are at bottom:
$updateDynu MYHOST.ddnsgeek.com user=MYUSER password=MYPASSWORD interface=ether1  

You should be able to use it the command line or in a script, and both logs and ":put". I'd recommend you cut-and-paste the function (without out the line above) to /system/script with same policy read,write,test policy, called "updateDynu". To have it run as periodically, just add a /system/schedule script with same policy with the "on-event" simply being "updateDynu" (or SAME of /system/script with the Dynu DDNS update code below).

Dynu DDNS Updater code


:global updateDynu 
:set updateDynu do={
    # handle parameters to Dynu "cmd function"
    :local ddnshost $1
    :local theinterface $interface
    :local ddnsuser $user
    :local ddnspass $password
    :local dynuGetUpdateUrl "https://api.dynu.com/nic/update?hostname=$ddnshost"
    
    # helper functions to print help and log...
    :local printUsage do={
        :put " Usage"
        :put "\$updateDynu <ddns_hostname> user=<dynu_user> password=<dynupass> interface=<WAN> [force=yes]"
    }
    
    # check that DDNS name is provided as 1st argument, error if not
    :if ([:typeof $1]!="str") do={
        $printUsage
        :local errmsg "ERROR: \$updateDynu requires a DDNS hostname [$ddnshost]"
        /log error $errmsg 
        :error $errmsg 
    }

    # check that DDNS name is provided as 1st argument, error if not
    :if (([:typeof $user]!="str") || ([:typeof $password]!="str")) do={
        $printUsage
        :local errmsg "ERROR: \$updateDynu requires a username and password [$ddnshost]"
        /log error $errmsg 
        :error $errmsg 
    }

    # if "interface=ether1" is provided use that, do not detect 
    # get the WAN ip address (removing /xx prefix)
    :local wanip 
    :if ([:typeof $theinterface]="str") do={
        /log/debug [:put "$ddnshost update using WAN interface: $theinterface "]
        :local wanipid [/ip/address/find interface=($theinterface)]
        :if ([:len $wanipid]!=1) do={
           :local errmsg "ERROR: \$updateDynu invalid interface $theinterface, found $[:tostr $wanipid]"
            /log error $errmsg 
            :error $errmsg  
        }
        :local wanipprefix [/ip/address/get $wanipid address]
        :set wanip [:tostr [:pick $wanipprefix 0 [:find $wanipprefix "/" ]]]
        /log/debug [:put "$theinterface got ipprefix=$wanipprefix ip=$wanip updating $ddnshost"]
        :if ([:typeof [:toip $wanip]]!="ip") do={
            :local errmsg "ERROR: \$updateDynu invalid /ip/address. prefix=$[:tostr $wanipprefix] ip=$[:tostr $wanip]"
            /log error $errmsg 
            :error $errmsg 
        }
        :set dynuGetUpdateUrl "$dynuGetUpdateUrl&myip=$wanip" 
    } else={
        /log/info [:put "$ddnshost no interface= provided, auto-detected based on http request be used"]
    }

    # is update needed?
    :local doUpdate false
    :local cacheDns [:tostr [:resolve $ddnshost]]
    :local resolvedDns [:tostr [:resolve $ddnshost  server=[:resolve NS1.DYNU.COM]]]
    :if ($resolvedDns!=$wanip) do={
        /log/debug [:put "will attempt update, $resolvedDns does not equal $[:tostr $wanip]"]
        :set doUpdate true
    }
    :if ($force~"(yes|true|y|1)") do={
        /log/debug [:put "will attempt update, force=yes for $resolvedDns"]
        :set doUpdate true
    }
    #/log/debug [:put "DDNS update: $doUpdate <= resolve=$resolvedDns cache=$cacheDns force=$force ip=$wanip host=$ddnshost"]
    
    # update dynu
    :if ($doUpdate) do={
        :onerror err in={
            /log/debug [:put "DDNS HTTP update started, using $dynuGetUpdateUrl"]
            :local dynuHttp [/tool/fetch http-method=get user=$ddnsuser password=$ddnspass url=$dynuGetUpdateUrl as-value output=user]
            /log/debug [:put "DDNS HTTP update finished, got: $[:tostr $dynuHttp]"]
            :if (($dynuHttp->"data")~"good") do={
                /log info [:put "DDNS $ddnshost updated from $resolvedDns to $[:pick ($dynuHttp->"data") 5 32]"]
            } else={
                :if (($dynuHttp->"data")~"badauth") do={
                    :error "** failed due to auth issue, $($dynuHttp->"data")" 
                } 
                /log warning [:put "WARNING: $ddnshost update reported not $($dynuHttp->"data")"]
            }
        } do={
            :local errmsg "ERROR: $ddnshost from $resolvedDns had HTTP issue: $err"
            /log error [:put $errmsg]
            :return [:nothing] 
        }
    } else={
        /log/info [:put "no update of $ddnshost needed <= resolve=$resolvedDns cache=$cacheDns ip=$wanip"]
    }
    :return [:nothing]
}

$updateDynu MYHOST.ddnsgeek.com user=MYUSER password=MYPASSWORD interface=ether1 

If things work at BOTH command line and script the same – which functions do. It means if you cut-and-paste to command line, it will should the errors in Terminal in RED. So you can edit, and try again. Once things go to /system/script, it is hard to spot errors. So Dynu having different scripts for the different cases is also not good – since you cannot test same code.
 
User avatar
mozerd
Forum Veteran
Forum Veteran
Posts: 912
Joined: Thu Oct 05, 2017 3:39 pm
Location: Canada
Contact:

Re: Script Execution Error - Dynu.com 7.13 was fine 7.15 no bueno

Tue Jun 11, 2024 5:36 pm

@Amm0
Your NEW code works beautifully ... Thank You ...
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12313
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script Execution Error - Dynu.com 7.13 was fine 7.15 no bueno

Wed Jun 12, 2024 3:16 pm

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...

Consistency is better...

Also is nice if RegEx (I have already posted on forum) is used for check hostname validity before submit.....
 
optio
Forum Veteran
Forum Veteran
Posts: 834
Joined: Mon Dec 26, 2022 2:57 pm

Re: Script Execution Error - Dynu.com 7.13 was fine 7.15 no bueno

Wed Jun 12, 2024 3:49 pm

There is no error now because script logic is put into function, I'm still hoping that MT will fix script error logging when :return called from main script code block...
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12313
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script Execution Error - Dynu.com 7.13 was fine 7.15 no bueno

Wed Jun 12, 2024 5:55 pm

The fundamental problem of the OP who followed a guide done with the feet...

Since users copy-and-paste without even realizing what they are doing, it is obvious that if the beginning of the script itself is wrong, everything else is useless.

Code: Select all

/system script
add name=Dynu
policy=read,write,test
:global ddnsuser "your_Dynu_username"

Note that you need to escape the special characters such as “ and $ and also to insert the \r\ and \n line control characters.
This denotes that the writer does not know what he is writing...
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3838
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Script Execution Error - Dynu.com 7.13 was fine 7.15 no bueno

Wed Jun 12, 2024 7:53 pm

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.
Last edited by Amm0 on Wed Jun 12, 2024 9:47 pm, edited 2 times in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12313
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script Execution Error - Dynu.com 7.13 was fine 7.15 no bueno

Wed Jun 12, 2024 9:04 pm

8) 

Who is online

Users browsing this forum: No registered users and 14 guests