I’ll digress a little from the main topic of the topic and give examples of the possibility of entering a line in the Terminal:
To enter a line from the Terminal, of course, you can write a small script using :terminal inkey like this:
:local EnterString do={
:local cont; :local string
:while ($cont!=13) do={
:if ([:len $string]<254) do={
:local key ([:terminal inkey])
:if ($key!=13) do={
:local char [[:parse "(\"\\$[:pick "0123456789ABCDEF" (($key >> 4) & 0xF)]$[:pick "0123456789ABCDEF" ($key & 0xF)]\")"]]
:set string ("$string"."$char")}
:set cont $key
}
}
:return $string}
This small function allows you to enter a string of up to 254 characters character by character. In this example, the input stops if the user presses the “Enter” key (Enter key code=$0D (13). Of course, character-by-character input allows you to use any other restrictions for the end of the input (for example, another ending character or the number of characters entered), which allows you to configure the input most flexibly.
It can be supplemented with different buns with instant verification of the entered characters, limit the length of the generated string, etc…
But, if you need it easier and faster, you can use such a feature: http://forum.mikrotik.com/t/script-input-from-console-works/120030/1
:local input do={:put $1; :return;}
:local login [$input "Enter login:"]
:local password [$input "Enter password:"]
:put "Login is [$login] and password is [$password]"
The trick is that it is empty: return from the Terminal always prompts you to enter a value. The end of the input is necessarily the “Enter” key.The only inconvenience will be the output of the word “value:” as an invitation before entering, but if it’s not annoying, then everything works fine.
It is convenient to use from interactive scripts configuration settings, etc…
Another possibility has appeared in the Router OS 7.11 - the use of :terminal ask. This new command is devoid of the inconvenience associated with the output of the prompt to enter the value :value. The end of the input is also necessarily the “Enter” key.
:global Answer [:terminal/ask "Do you agree to use Router OS 7?"]
:put $Answer
Well, or something like that (for example):
{
:global Answer []
:while ($Answer!="yes") do={
:set Answer [:terminal/ask "Do you agree to use Router OS 7?"]
}
}
You can also specify any input prompt if you use the “preinput” parameter:
:global userinput [/terminal/ask preinput="preinput>" prompt="Some text that in prompt"]