Community discussions

MikroTik App
 
RamonetNet
newbie
Topic Author
Posts: 28
Joined: Thu Dec 21, 2017 6:50 pm

catch 22 importing a RSC file

Tue Jan 11, 2022 2:47 pm

Good morning. We have a RSC file with this line:
/interface bridge port
  add bridge=bridge_name interface=ether9
It runs OK the first time, using the command "import my_config.rsc verbose=yes"
but if there are errors in the lines after this one, once we fix the error and import the file again,
we get the error
failure: device already added as bridge port
So, we decided to include the line
remove bridge_name
just before the "add bridge"

The problem is that in certain situations we get the error message "no such item", and the import fails,
and we get into the initial situation, in a loop.

So I think the "remove" sentence must be "conditional" the the "existence" of this bridge,
but I dont know how to code this.

The pseudo-code can be similar to :
if exists(bridge-name) then delete(bridge-name)
Can someone provide me a sample or a pointer to a good documentation ?

Thanks.
 
accarda
Member Candidate
Member Candidate
Posts: 208
Joined: Fri Apr 05, 2019 4:06 pm
Location: Italy

Re: catch 22 importing a RSC file

Tue Jan 11, 2022 6:11 pm

You can start by reading about scripting from here:
https://help.mikrotik.com/docs/display/ROS/Scripting

There you can also find a way to intercept errors when your code is part of a do section by using on-error statement.
https://help.mikrotik.com/docs/display/ ... timeerrors
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3441
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: catch 22 importing a RSC file

Tue Jan 11, 2022 10:11 pm

Likely you have a reason for using RSC... but if you're doing this on the same router AND want the entire config replaced, Backup/Restore from the Files menu might be easier. The "export" file is designed to be "import" to into an unconfigured router - as you found out, you can NOT just do "export", and then "import" same file back without adding code yourself. (And it unfortunate there is not an option to have RouterOS do this task for you)

But another good example of the needed ":if [] do={} else={} on-error={}" syntax that would have to be added to an RSC, is actually the default configuration for the box, which you can see using for the specific router you're dealing with using:
/system default-configuration print

Another forum posting shows default config from the Audience: viewtopic.php?p=903641&hilit=audience+config#p903639

Who is online

Users browsing this forum: No registered users and 26 guests