Script input from console ... works!

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.

No mention of this behaviour found at https://wiki.mikrotik.com/wiki/Manual:Scripting and https://wiki.mikrotik.com/wiki/Manual:Scripting-examples

dennis46 - it’s a nice lifehack!! Thanks! :slight_smile:

It’s not “Undocumented” and it’s probably not a “feature” :slight_smile:. 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 :smiley:.

Ok! Thanks for explanation! :slight_smile:

This does not work for me in v6.47. I’m not getting prompted for input and this is printed then:

Login is and password is

Is there a working user input in v6.47? I also did not succeed with http://forum.mikrotik.com/t/scripting-asking-user-for-input/79678/1

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! :open_mouth:

\... :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?

There is actually now an /terminal/ask in v7.12beta1.

{
  :local myhelp "You can ask questions now!"
  :local myquestion "What do you want to ask?"
  :local myanswer [/terminal/ask preinput=$myhelp prompt=$myquestion]
  :put $myanswer
}

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

Create a separate non-interactive version…