How to import a script, an rsc file, or the output of an ‘export’ command
An rsc file is simply a plain text file with an .rsc file extension so that the Mikrotik knows it is a script to be executed. It is the output of an export command. Look at the following screenshot to see what commands I entered to get this output.
The export from this is:
/ip firewall nat add action=masquerade chain=srcnat comment="default configuration" disabled=no out-interface=\ ether1-gateway to-addresses=0.0.0.0
If I wanted to enter this into another router, I could either copy and paste this single line into a Terminal and hit enter, or I could make it into an rsc file and import that. For something as short as this it doesn’t make a big difference, but you could import 1, 10, or 100+ lines of a script with a single rsc file.
To create an rsc file, simply copy and paste the text into a basic text editor – something like Notepad, or a “programmer’s text editor” like Notepad++, Sublime Text, TextMate, gedit, TextWrangler, or others. Don’t use Word, don’t use Evernote, use a basic text editor. You want it to preserve exactly what you entered, to not add any extra formatting on its own, and to allow you to name it with any file extension you want.
Do a Save As in the text editor and give the file any name you want, but add “.rsc” at the end. Like myscript.rsc.
Next you have to get that rsc file onto the router.
The simplest way is to open the Files window in Winbox and drag in your myscript.rsc from your Desktop/Windows Explorer. The file will upload to the router and appear in the file list. You can also do this over FTP or even with an SMB shared folder, but drag-and-drop is simple and works fine.
To import an rsc file you have to open a Terminal window (or hit New Terminal at the left of Winbox). At the command prompt, type import myscript.rsc. If all goes well you should get a response saying something like:
Opening script file testfile.rsc Script file loaded and executed successfully
Now your script has been loaded as if you had entered the whole thing manually.
A note on Backslashes
The backslash - \ – gets added to signify that the line is being continued on the following line because it is too long to fit on the screen. It’s basically to make it more readable in the terminal window. They more or less get ignored when imported. Pay attention to the backslashes in the following.
If I make my Terminal window super skinny, it will export like this:
/ip firewall nat add action=masquerade chain=srcnat \ comment="default configuration" \ disabled=no out-interface=\ ether1-gateway to-addresses=\ 0.0.0.0
If I make it a bit wider it will export like this:
/ip firewall nat add action=masquerade chain=srcnat comment="default configuration" \ disabled=no out-interface=ether1-gateway to-addresses=0.0.0.0
…and if I make it super wide it will export like this
/ip firewall nat add action=masquerade chain=srcnat comment="default configuration" disabled=no out-interface=ether1-gateway to-addresses=0.0.0.0
The only difference between them is how much text would fit in a single line on the Terminal window I had open. It doesn’t have a bearing on the script itself.