실행 시 "명령 이름이 잘못되었습니다" 발생, 예상 오류

실행 시 "명령 이름이 잘못되었습니다" 발생, 예상 오류

오류 메시지가 나타납니다.

 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)

관련 정보