riflooping
riflooping

Reputation: 1

Fetch using mtlogin not working on RouterOs 7.1.5

I am currently encountering a problem.

When I want to download a file on a mikrotik in 6.48.6 using mtlogin and fetch tool, it works perfectly and the script waits until the router has finished downloading to send a "quit".

However, when trying the same manipulation on a router in version 7.1.5, the "quit" is sent directly, thus stopping the download because of the letter Q and thus sending "uit" thereafter in the prompt.

The prompts are similar for 6.48.6 and 7.1.5, and even when trying to add expects in the script, the result is the same. I think the problem is in this part of the code, but don't know how to fix it.

# Run commands given on the command line.
proc run_commands { prompt command } {
    global do_interact in_proc
    set in_proc 1

    # escape any parens in the prompt, such as "(enable)"
    regsub -all "\[)(]" $prompt {\\&} reprompt

    # handle escaped ;s in commands, and ;; and ^;
    regsub -all {([^\\]);} $command "\\1\u0002;" esccommand
    regsub -all {([^\\]);;} $esccommand "\\1;\u0002;" command
    regsub {^;} $command "\u0002;" esccommand
    regsub -all {[\\];} $esccommand ";" command
    regsub -all {\u0002;} $command "\u0002" esccommand
    set sep "\u0002"
    set commands [split $esccommand $sep]
    set num_commands [llength $commands]
    for {set i 0} {$i < $num_commands} { incr i} {
    send -- "[subst -nocommands [lindex $commands $i]]\r"

    if { [lindex $commands $i] == "/system/reboot"} {
        send "y\r"
    }

    expect {
        -re "^\[^\n\r]*$reprompt"       {}
        -re "^\[^\n\r ]*>>.*$reprompt"  { exp_continue }
        -re "\[\n\r]+"          { exp_continue }
    }
    }
    
    if { $do_interact == 1 } {
    interact
    return 0
    }

    send "quit\r"
    expect {
    -re "^WARNING: There are unsaved configuration changes." {
                         send "y\r"
                         exp_continue
                        }
    "\n"                    { exp_continue }
    "\[^\n\r *]*Session terminated"     { return 0 }
    timeout                 { catch {close}; catch {wait};
                          return 0
                        }
    eof                 { return 0 }
    }
    set in_proc 0
}

That's how it looks like

Does anyone have a solution?

Upvotes: -1

Views: 856

Answers (1)

riflooping
riflooping

Reputation: 1

I just find the solution in mtlogin at line 625!

foreach router [lrange $argv $i end] {
set router [string tolower $router]
send_user "$router\n"

# Figure out prompt.
set prompt "] >  "   #Just added a second whitespace after >
# alteon only "enables" based on the password used at login time
set autoenable 1
set enable 0

Hope it's gonna help you

Upvotes: -1

Related Questions