执行时出现“命令名称无效”,预期错误

执行时出现“命令名称无效”,预期错误

我收到一条错误消息:

 invalid command name "
    while executing
""\r""
    invoked from within
"expect {
    -ex "--More--" {send -- " "; exp_continue}
     "*>" {send "exit \r";"\r"}
}"
    (file "./scriptprueba4.sh" line 12)

在一个expect曾经运行良好的脚本中。我修改了脚本以便从中获取信息show CDP neighbor,然后出现错误。

这是代码:

#!/usr/bin/expect -f
#!/bin/sh
set DATE [exec date +%F]
spawn telnet 111.111.1.111
expect "Username:"
send "user\r"
expect "Password: "
send "this.is.the.pass\r"
expect "*>"
send "show cdp neighbors \r"
log_file -noappend CDP.dat
expect {                               #this is the part i just modified and caused the error.
    "More--" {send " "; exp_continue}
    ">" {send "exit \r"; "\r"}
}
expect "$ "                            #I want this part of the code to be executed after "$" but the script stops before doing it 
send "tail -n+6 CDP.dat > CDP2.dat\r"
expect "$ "
send "./primeros3.sh \r"
expect "$ "
send -- "tr -d '\\r' < CDPyPuerto.dat | awk '{ printf \"%s %s\", \$0, (length(\$1) > 16) ? OFS : ORS}' > TablaCDP.dat \r"
expect "$ "

代码中不起作用的部分用于处理多页终端输出,脚本工作正常,直到:

expect {                               
    "More--" {send " "; exp_continue}
    ">" {send "exit \r"; "\r"}
}

有什么帮助吗?

更新:我已经这样更改了代码:

#!/usr/bin/expect -f
#!/bin/sh
set DATE [exec date +%F]
spawn telnet 111.111.1.111
expect "Username:"
send "user\r"
expect "Password: "
send "this.is.the.pass\r"
expect "*>"
send "show cdp neighbors \r"
log_file -noappend CDP.dat
expect -ex "--More--" {send -- " "; exp_continue}
expect "*>"
send "exit \r"
expect "$ "
send "tail -n+6 CDP.dat > CDP2.dat\r"
expect "$ "
send "./primeros3.sh \r"
expect "$ "
send -- "tr -d '\\r' < CDPyPuerto.dat | awk '{ printf \"%s %s\", \$0, (length(\$1) > 16) ? OFS : ORS}' > TablaCDP.dat \r"
expect "$ "

现在错误显示:

send: spawn id exp4 not open
    while executing
"send "tail -n+6 CDP.dat > CDP2.dat\r""
    (file "./scriptprueba4.sh" line 16)

相关内容