“Nome do comando inválido” durante a execução, Expect error

0

Estou recebendo um erro que diz:

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

em um script expect que costumava funcionar bem. Eu modifiquei o script para obter informações de show CDP neighbor e, em seguida, o erro apareceu.

Este é o código:

#!/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\", \
expect {                               
    "More--" {send " "; exp_continue}
    ">" {send "exit \r"; "\r"}
}
, (length(\) > 16) ? OFS : ORS}' > TablaCDP.dat \r" expect "$ "

A parte do código que não está funcionando, é usada para manipular várias páginas de saída do terminal, o script está funcionando bem até:

#!/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\", \
send: spawn id exp4 not open
    while executing
"send "tail -n+6 CDP.dat > CDP2.dat\r""
    (file "./scriptprueba4.sh" line 16)
, (length(\) > 16) ? OFS : ORS}' > TablaCDP.dat \r" expect "$ "

Alguma ajuda?

Atualização: alterei o código desta maneira:

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

O erro agora diz:

#!/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\", \
expect {                               
    "More--" {send " "; exp_continue}
    ">" {send "exit \r"; "\r"}
}
, (length(\) > 16) ? OFS : ORS}' > TablaCDP.dat \r" expect "$ "
    
por Cesar Alejandro Villegas Yepez 03.02.2017 / 18:49

0 respostas