首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用不使用RouterOs 7.1.5的mtlogin获取

使用不使用RouterOs 7.1.5的mtlogin获取
EN

Stack Overflow用户
提问于 2022-04-22 09:54:39
回答 1查看 413关注 0票数 0

我目前遇到了一个问题。

当我想在6.48.6中的mikrotik上下载一个文件时,使用mtlogin和fetch工具,它工作得很好,脚本一直等到路由器下载完发送一个“退出”。

但是,在7.1.5版本的路由器上尝试相同的操作时,“退出”将直接发送,从而由于字母q而停止下载,然后在提示符中发送"uit“。

对于6.48.6和7.1.5,提示类似,即使试图在脚本中添加期望,结果也是一样的。我认为问题在代码的这一部分,但不知道如何修复它。

代码语言:javascript
复制
# 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
}

就像这样

有人有解决办法吗?

EN

回答 1

Stack Overflow用户

发布于 2022-05-16 13:10:10

我只是在第625行的mtlogin中找到了解决方案!

代码语言:javascript
复制
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

希望它能帮到你

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71966844

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档