Adding scripts in reset configuration script

Hello,
Right now I have a reset configuration script wich is working if i use it to reset the mikrotik router. I wanted to add two scripts wich should be automaticly in the router if I reset it with my reset configuration script. My problem is that it doesn’t work with the added script. I couldn’t connect with the Router and had to use the default reset. What is wrong with the following code:

/system script
add dont-require-permissions=yes name=add-Alpine owner=admin policy=\
    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="\
    \r\
    \n/container/add file=disk2/images/linux.tar interface=veth1 root-dir=disk1/docker/linux_root 
    mounts=linux_data envlist=linux_envs logging=yes;


/system script
add dont-require-permissions=yes name=container-run owner=admin policy=\
    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="\
    \r\
    \n:local myCon do={:put "container"; :return};\r\
    \n:local containerlist [$myCon];\r\
    \n:put "Docker is running";\r\
    \n/container start $containerlist;\r\
    \n/container shell $containerlist;\r\
    \n/delay 1;\r\
    \n/container stop $containerlist;

Thank you for your help

On both is missing "at the end, for example, and without checking anything else, like the mess you do with the " inside the scripts…

What you try to do with that???

:local myCon do={:put "container"; :return}
:local containerlist [$myCon]

Is not it better make to work the scripts first, then export the scripts from the terminal without trying to convert the scripts yourself?

My Code is already working the way it should work. Just wanted to add it in the reset configuration script.
With the command ":local myCon do={:put "container";:return}" the terminal looks like this :

[admin@DISE_LAB11] /system/script> run container-run
container
value:

There i just give the number of a container i want to run. As example container number "0". And with the second line it gives the input to the variable $containerlist wich will be getting used in the following commands

/container start $containerlist;
/container shell $containerlist;
delay 1;
/container stop $containerlist;

Thank you for helping me.
Now I have another problem where maybe you or someonelse could help me. If i write the following code in Terminal everthing seems to be normal.

/system script
add dont-require-permissions=no name=container-run owner=admin policy=\
    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="\
    \r\
    \n:global myCon do={:return};\r\
    \n:global containerlist [$myCon];\r\
    \n/container start $containerlist;\r\
    \n/container shell $containerlist;\r\
    \n/delay 1\r\
    \n/container stop $containerlist;"

But if I look in the script list what is logged it will show me the following code:

:global myCon do={:return};
:global containerlist [];
/container start ;
/container shell ;
/delay 1
/container stop ;

My variables are lost and i can't see why it behave like this.

This is a rude answer, if you were that good you didn't ask for help.


I understood that they had to be scripts that had to be executed during the reset, not interactive scripts to be kept ready for later use from the terminal.
Here is the reason for the question.
I already know what the code do:

(I could also assume that where you copied the code from, it was inspired by my function, or that you copied it yourself)

Now I reading the rest of your reply...

Without deep inspecting the rest, missing all \ before $


As I have already written, you are not able to convert "by hand" the script to script inside the "add script" function,
so first insert them from winbox and then export them, and maybe they are correct.

I m sorry. I didnt want to appear like i m rude.

Okay i will try it. Thank you

this is very old (October 2024) but did you make it work? /container add in a system script? I just posted this. Spent a full day and could make it work. Containers in RAM on hEX Refresh