How to export, import and troubleshoot scripts

Exporting Script:

If you have a router OS configuration you would like to use on another model of device the easiest way of bringing it across is to export the configuration file into a script, this can be simply done by opening up a new terminal from the main menu then typing in export file="filename you would like"


Once this has been compleated you are able to download this from the files menu, in here you can either drag and drop it to your desktop if you are using winbox otherwise you can use the download button on webfig


Importing scripts:

There are a couple different ways to do this and the common ones will either be using the run after reset command or the import command from a blank router.
To import from a blank router all you need to do is go to the new terminal window and use the import file-name="filename.rsc" command once the file has been uploaded to the device
After you hit enter terminal will look like it has frozen for a little while but then should say that the script has been loaded successfully :)


The second common option is to use run after reset, all we have to do for this is upload the file again but this time making sure that the file is in the flash directory if there is one otherwise it will be deleted on reboot and will not get imported, then go to the system/reset-configuration menu and select out script in the run after reset section. We do not need to worry about anything else here as the do default configuration will get over ridden and ignored if we are using run after reset


After the device comes back online you need to then look at the log to make sure there are no errors with the configuration, as you can see below the only error was a bad login so it looks like this configuration imported correctly


Troubleshooting scripts:

When troubleshooting there are 2 types of errors, syntax errors where the command was entered incorrectly so router OS does not understand it and then there are configuration errors.
What you can see below is a syntax error and luckily it will let us know exactly where the error is.


From here we need to go and see what the error actually is, we can do this by opening the RSC file in a text editor of our choice and looking at the line and column


you can see that at this location is there is a command adding a IP pool and the command in question is addresses= so from here we need to check this in winbox


Looks like we have confirmed the issue, from here we need to then check what is the right command, we can see the list of available commands by hitting the tab button so lets remove the bad command and see what we can do from here


Ranges looks like the best fit but I am not 100% sure if this is the right thing so I will look up Mikrotik help ip/pool for the Mikrotik help page and find out what this feature does


SO now we know ranges is what we want we can double check that winbox accepts this and then update out script


After fixing up that syntax error we are now getting a new error but this time it is not giving us a line number, this is due to the error being with the configuration its self and not the syntax, this is a little more annoying to troubleshoot as it will import the configuration up to the error so you will need to do a reboot.


While this does not directly give you a line to work on as stated above it will import the configuration up until the error so all we have to do is type in export in our terminal and check the difference between the output and out script.
As seen below when doing a comparison everything after the address pool has not been added so that gives us an indication that the issue is on line 29


From the error above we already know this has to do with the interface selection of this line and we can tell this is a typo as the e is missing in bridge but if we didnt know what the correct options were for this we can take away the interface and then hit tab to see what the available options are. Not that not everything will have this options like the address= so you will need to consult the Mikrotik help/wiki if the error message is unclear :)