Cancel Paste to Terminal

I have a rather long initial router configuration script that is used to setup new routers. The script assumes that that router is void of any configuration and all you have to do is set a few variables at the top and then paste the whole script into the terminal.
Some times the technician that is tasked with configuring a new router isn’t fully awake and attempts to paste the script into the terminal without first removing the default configuration first. I have then since been attempting to make the script more foolproof, but even better would be if I could just cancel or interrupt the paste. But only way I know to do this is have the user press Ctrl+C.

Currently I have this small block of code to interrupt the paste:

:if ([:len [/interface find name=ether1-gateway]] != 0) do={
    :put "### Reseting configuration without default configuration."
    :put "### Press CTRL+C to cancel."
    :put "### 10"
    :delay 1
    :put "### 9"
    :delay 1
    :put "### 8"
    :delay 1
    :put "### 7"
    :delay 1
    :put "### 6"
    :delay 1
    :put "### 5"
    :delay 1
    :put "### 4"
    :delay 1
    :put "### 3"
    :delay 1
    :put "### 2"
    :delay 1
    :put "### 1"
    :delay 1
    :put "### Restarting..."
    /system
    reset-configuration keep-users=no no-defaults=yes skip-backup=yes
}
y

I was thinking that maybe I could just disconnect them from the telnet session, but not sure how to go about doing that. Anyone know if this is possible?
Any other ideas?

Embed your configuration and interruption code in a /system script and execute this script as last part of your to-be-pasted text.

That would only work if the whole configuration script is error-free. Pasting to terminal gives you the advantage of allowing errors in the script, which can be useful when working with multiple hardware types and software versions..

Doing it like that would also prevent the adding of “/system upgrade upgrade-package-source”.
See: (Thread) Script adding upgrade source

Not being able to import a .rsc file if it has even the slightest error is a problem that I have raised as an issue
again, and the reply is that they are looking into a solution for that. Also a method of reporting errors in the processing
(while continuing with the next statement)

E.g. when you try a “reset configuration” and import of a .rsc file as configuration, and there is an error in the
processing, you are left with a dead router and no way to determine what went wrong. I think it should process
the .rsc until the end and leave a logfile in the filesystem you can download and examine.

Oh yeah, I agree. I even raised this a while back.
I mean the current import functions ok, but a special way to tell it to simulate the import as paste to terminal and write a log file with everything, just as if you had pasted it into the terminal and copied the terminal to file.

Anyway, this is a little off topic. ^^;

Why is this off topic?
When the reset-configuration would be able to import a .rsc file with slight problems, your whole issue
of pasting text in a window would not exist!

I recently tried to configure a router this way. It was identical hardware but still there were issues. And
it is impossible to debug because when the import fails I had no access to the router, it had apparently
not reached the state of a configured LAN with IP address etc.
So I had to work around it the same way as you indicate, by pasting commands in the session, which
I think is an ugly solution.

Ah, now I see what you mean. I have been thinking about that, but like I wrote above, there are still commands that can’t be done in a script/import and has to be pasted.
I read somewhere that you can maybe even replace the default configuration using NetInstall, but I have not been able to find it.

But mostly the question I wanted to raise in this thread was if anyone knew of any other ways to cancel or interrupt the paste to terminal.
Best I can think of is to force a reboot. Or like in my example above, a configuration reset.

I think I just found the ultimate answer to this question of mine.

/quit

Using this in the terminal instantly disconnects you and stops furter pasting. As an added bonus, it leave the terminal window open, so you can actually see what happened and even give feedback to the user.

So I wrote this in my paste configuration:

:if ([:len [/interface find name=ether1-gateway]] != 0) do={
    :log warning "Default configuration detected. Please reset configuration without default configuration."
    :put "Default configuration detected. Please reset configuration without default configuration. Use this command:"
    :put "/system reset-configuration keep-users=no no-defaults=yes skip-backup=yes"
    :put ""
    /quit
}

End result:

[admin@Mikrotik] > :if ([:len [/interface find name=ether1-gateway]] != 0) do={
{...     :log warning "Default configuration detected. Please reset configuration without default configuration."
{...     :put "Default configuration detected. Please reset configuration without default configuration. Use this command:"
{...     :put "/system reset-configuration keep-users=no no-defaults=yes skip-backup=yes"
{...     :put ""
{...     /quit
{... }
Default configuration detected. Please reset configuration without default configuration. Use this command:
/system reset-configuration keep-users=no no-defaults=yes skip-backup=yes

interrupted