Community discussions

MikroTik App
 
karaYusuf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 54
Joined: Wed Oct 12, 2022 11:07 am

adding scripts in reset configuration script

Thu Oct 13, 2022 2:00 pm

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
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: adding scripts in reset configuration script

Fri Oct 14, 2022 2:33 am

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?
 
karaYusuf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 54
Joined: Wed Oct 12, 2022 11:07 am

Re: adding scripts in reset configuration script

Fri Oct 14, 2022 7:44 am

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.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: adding scripts in reset configuration script

Sat Oct 15, 2022 1:49 am

My Code is already working the way it should work.
This is a rude answer, if you were that good you didn't ask for help.

What you try to do with that???
[…]
[…]
There i just give the number of a container i want to run. […]
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:
viewtopic.php?p=934934#p934069
(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...
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: adding scripts in reset configuration script

Sat Oct 15, 2022 2:02 am

If i write the following code in Terminal everthing seems to be normal.
/system script
add […] source="\
[…]
    \n/container start $containerlist;\r\
[…]
But if I look in the script list what is logged it will show me the following code:
[…]
/container start ;
[…]
My variables are lost and i can't see why it behave like this.

Without deep inspecting the rest, missing all \ before $

Is not it better make to work the scripts first, then export the scripts from the terminal without trying to convert the scripts yourself?
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.
 
karaYusuf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 54
Joined: Wed Oct 12, 2022 11:07 am

Re: adding scripts in reset configuration script

Mon Oct 17, 2022 9:08 am

My Code is already working the way it should work.
This is a rude answer, if you were that good you didn't ask for help.
I m sorry. I didnt want to appear like i m rude.
 
karaYusuf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 54
Joined: Wed Oct 12, 2022 11:07 am

Re: adding scripts in reset configuration script

Mon Oct 17, 2022 9:09 am

[…]

Without deep inspecting the rest, missing all \ before $

Is not it better make to work the scripts first, then export the scripts from the terminal without trying to convert the scripts yourself?
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.
Okay i will try it. Thank you

Who is online

Users browsing this forum: diamuxin, JDF, philipp84 and 22 guests