简体   繁体   English

使用 mtlogin 获取在 RouterOs 7.1.5 上不起作用

[英]Fetch using mtlogin not working on RouterOs 7.1.5

["

I am currently encountering a problem.<\/i>我目前遇到一个问题。<\/b><\/p>

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".<\/i>当我想使用 mtlogin 和 fetch 工具在 6.48.6 中的 mikrotik 上下载文件时,它运行良好,脚本等待路由器完成下载以发送“退出”。<\/b><\/p>

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.<\/i>但是,当在 7.1.5 版本的路由器上尝试相同的操作时,直接发送“退出”,因此由于字母 Q 而停止下载,因此在提示符中随后发送“uit”。<\/b><\/p>

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> 6.48.6 和 7.1.5 的提示类似,即使尝试在脚本中添加期望,结果也是一样的。<\/b> I think the problem is in this part of the code, but don't know how to fix it.<\/i>我认为问题出在这部分代码中,但不知道如何解决。<\/b><\/p>

# 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
}

I just find the solution in mtlogin at line 625!我只是在第 625 行的 mtlogin 中找到了解决方案!

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希望它会帮助你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM