I found an instresting undocumented (?) solution to input values from terminal to script.
It looks like this.
=== sample script ===
:local input do={:put $1;:return}
:local login [$input “Enter login”]
:local password [$input “Enter password”]
:put “Login is [$login] and password is [$password]”
=== terminal outeput ===
[admin@MikroTik AP] /ppp secret> /system script run 1
Enter login
value: mike
Enter password
value: jdajshdjadh
Login is [mike] and password is [jdajshdjadh]
[admin@MikroTik AP] /ppp secret>
So if you use :return without any params you get input from terminal.
It’s not “Undocumented” and it’s probably not a “feature” . MikroTik does that if you don’t fill a required value. Try: /ping - it will ask you for address (as it’s a required argument). The same when you want to remove something (/ip address remove), not specifying what - it’ll ask you for clarification. And does the same here. Probably noone thought that this “asking for clarification” can be used here that way .
Thanks you so much and I was looking for this script. Put it like this with a starting “{” and a ending “}” in terminal. When using in script and schedule as stated earlier. I have put :terminal style escaped; in to have the text be displayed in a different color.
I played with cuu and el to get the field to enter behind the description but did not manage that.
:terminal
cuu -- move cursor up
el -- erase line
inkey -- read key
style -- set output text style
:local input do={:terminal style escaped; :put $1; :return;}
:local login [$input "Enter login:"]
:local password [$input "Enter password:"]
:put "Login is [$login] and password is [$password]"
Enter login
value: test
Enter password
value: test1
Login is [test] and password is [test1]
Darn even better than expected!
\... :put [:typeof $login]; :put [:typeof $password];
Enter login
value: 1234
Enter password
value: false
num
bool
Hi the whole thing works for be but I did not get the part where you said
Put it like this with a starting “{” and a ending “}” in terminal. When using in script and schedule as stated earlier.
.
The script where I use the input (if there is nothing set in the global environment) is also scheduled to run after interval… but it fails. It only runs perfectly if i run from the terminal… Can you please help me out?
All variables are :local and as soon the script has ende those are destroyed. To make those :global replace :local with :global.
The {} allows in terminal to run it as one script. Otherwise every line intepreted on it’s own and all variables are destroyed after pressing Enter…unless you use :global.
Thanks for the ideas but I think I failed to explain properly.
I have a script which takes the input and sets as a global variable before doing further things. The scripts works perfectly when I run it from the terminal. But I want the script to run using scheduler too. When the scheduler runs the script, it should not ask for the user input but rather take in the default value.
FYI: I do not wish for an upgrade to the beta version. My ROS is 7.11