Hello everyone. I am trying to implement a nested :do {} on-error{} script. The idea is to have a mother do loop to check if the script fails or not and then inside the child do and on-error loop is used to prevent the script action timeout error while signing the certificates.
The problem is if something fails inside the child do loop, it is not caught by its own on-error section but rather it goes directly to the on-error section of the mother. can anyone help me out to solve the issue?
One possible way to solve the issue is to increase the script action timeout so that the certificates gets signed or may be some special command which will ensure that the certificates are signed regardless of the timeout.
I have posted the script for your reproduction. Thanks a lot for your time and help.
In my opinion, using on-horror is a crap way to write scripts.
But obviously it’s my personal opinion, on the other hand I can’t help it if things aren’t done right.
Also, still using 6.2 on 2023, just one version of decades ago, denotes a few things, which I don’t even want to write about, they’re so obvious…
Created: Apr 18 2023
[…]
Tested on: ROS 6.2
FYI:
Is needed 3 minutes for just the 8k SSH key on “CCR 2116”…
Is needed 25 minutes for just the 8k SSH key on “hEX S”…
I don’t even want to imagine the time it takes in an older device with 6.2 just for the 8k SSH key…
I am sorry I did not get you properly? Is it you using 6.2 or you are saying I am? I am using 7.9 and CHR on could. The script is supposed to run there.
I also checked the time required for the keys to be generated and they are close to a minute only.
YOU wrote that you tested the script from version 6.2…
Don’t you read what you post?
And where did you write it on first post?
One more reason why on-error is not necessary, just write the script well, if the used machines are so powerful…
One more thing… If you write “Compatible Versions: ROS 6.x” it must be true, you shouldn’t use syntax that only works on RouterOS v7.x
So how did you test it on v6? “Tested on: ROS 6.2 - 7.9”
The comments alone are full of mistakes, without considering the mess rest… I would never put (my) name on it…
YOU wrote that you tested the script from version 6.2…
Don’t you read what you post?
I see the script is in development mode still and thus the default header. When you said about wrong scripting, I thought the main content of the script.
One more reason why on-error is not necessary, just write the script well, if the used machines are so powerful…
Yes the machine is powerful but the use of on-error is mainly a failsafe protection since the intention of the script is not to run only in 7.9 but also in older versions from 6.2 and onwards
One more thing… If you write “Compatible Versions: ROS 6.x” it must be true, you shouldn’t use syntax that only works on RouterOS v7.x
So how did you test it on v6? “Tested on: ROS 6.2 - 7.9”
So far I have tested the script to be working till 6.8 and there since the machine was not so powerful, the nested on-error issue was found due to more time to generate the key and thus the post.
The comments alone are full of mistakes, without considering the mess rest… I would never put (my) name on it…
Yes I agree that the comments are misleading but the post was to seek help for the main content of the script but not the comment. As a DevOP we both know that it is a common practice to update the comments at then end of everything (during the testing and QA)
You thought correctly, and on that I have nothing more to add…
Off to a bad start…
Already so it is not compatible with v6…
And I repeat that it is better that I do not comment on the desire to use it on such old versions full of hacks
already known by everyone (except those who use them, apparently) worldwide…
Already so it is not compatible with v6…
And I repeat that it is better that I do not comment on the desire to use it on such old versions full of hacks
already known by everyone (except those who use them, apparently) worldwide…
Hahaha true… then I guess I will stick to 7.x only but then also the nested on-error thing stays… what can be done for that? any help would be appriciated
I’m not the MikroTik programmer who made some choices I DO NOT agree with.
The default timeout “seems” to vary, more is loaded the CPU, the slower it goes…
The 3 minute and 25 minute tests are real, I haven’t written it just for write something.
Since the RouterBOARD doesn’t have the RTC I think they “calculate” the time with approximation starting from a known or estimated date.
\
Is it possible to have the whole script inside another mother :DO loop?
Actually I do not use main script “:do” or loops at all, but I do not see any reason for not use :do if really is needed.
I prefer to prevent errors, instead of dealing with them when they happen…
Of course it’s sometimes impossible to prevent them all, but I’d rather control than be controlled…
so that you can handle that error which will not break code execution (same as try-catch statement in some programming languages). It is better to write more strict code as rextended mentioned above with conditions to avoid errors in first place if you have code flow that needs to be mandatory, since having just logging in on-error block will not describe which error is actually occurred because there is no some error variable (afaik) in that block which will contain error message (but it would be nice that scripting engine provides that). When you have optional code execution in flow then
One pratical example of expected error, because RouterOS can not handle the problem, is with :resolve…
I’m forced to use on-horror when I try to resolve one domain, because RouterOS instead to reply with NXDOMAIN cause one error that block the script…
I have a similar problem, did I get it right, you cannot have on-error={} inside loops ?
I have this below code where I am trying to resolve name to IP inside a loop, and script breaks if domain name is invalid, if I add on-error it breaks with “expected end of command”.
Is the only option to use on-error outside of a loop ?
# define variables
:local list
:local comment
:local newip
:local oldip
# Loop through each entry in the address list.
:foreach i in=[/ip firewall address-list find] do={
# Get the first five characters of the list name
#:set list [:pick [/ip firewall address-list get $i list] 0 5]
:set list [/ip firewall address-list get $i list]
# If they're 'adr_ip_', then we've got a match - process it
:if ($list = "adr_ip_list") do={
# Get the comment for this address list item (this is the host name to use)
:set comment [/ip firewall address-list get $i comment]
:set oldip [/ip firewall address-list get $i address]
# Resolve it and set the address list entry accordingly.
: if ($newip != $oldip) do={
:set newip [:resolve $comment]
/ip firewall address-list set $i address=$newip
}
# if I enable this here, I get error "expected end of command" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< HERE <<<<<<<<<<<<
# on-error={};
:put $comment;
:put $newip;
}
}