Community discussions

MikroTik App
 
riflooping
just joined
Topic Author
Posts: 2
Joined: Fri Apr 22, 2022 11:48 am

RouterOS over 6.48.6 & Rancid

Mon May 09, 2022 12:57 pm

Hi erveryone !


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 with version over 6.48.6, 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 over, 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:

Image

Does anyone have a solution?
 
riflooping
just joined
Topic Author
Posts: 2
Joined: Fri Apr 22, 2022 11:48 am

Re: RouterOS over 6.48.6 & Rancid

Mon May 16, 2022 4:12 pm

Hi everyone,
I just found the solution, in mtlogin script 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 !

Who is online

Users browsing this forum: Bing [Bot], coffee1978, DanMos79, EsaqzpHot, icemending and 91 guests