S
S
Sergey Torop2018-06-05 13:32:11
Perl
Sergey Torop, 2018-06-05 13:32:11

How to suppress unnecessary characters when running an Expect script with switches?

Good afternoon, I
automate work with network switches, execute the necessary commands with a script.
I checked the work with many (successfully), but I came across an ode to a piece of iron, where, when exchanging data, it
sends something that makes the script freeze, does not wait for the expected output.
If you login via ssh to the switch *by hand*, then here is an example of a successful login:
# /usr/bin/ssh -e none [email protected]
Password:
Welcome to console
Enter username: superuser
Enter terminal type: vt100
COREHOST:1:> help system
: namespace for system parameters
spawn ssh -o PubkeyAuthentication=no [email protected]
Password:
Welcome to console
Enter username: superuser
Enter terminal type: vt100
COREHOST:1:> ^[[62;13R
i.e. successfully entered the piece of iron, but it spat out a certain sequence
"^[[62;13R" (possibly ESC characters) which are not expected.
I use Expect, tried the Perl module NET::SSH::Expect - the situation is similar.
Please tell me what these characters could be, cat. appear when only
scripts are running (ssh works successfully with hands on a piece of iron) and is it possible to somehow filter / suppress them?
ps. changed terminal type, did not help.
I use this script:
#!/usr/bin/expect -f
set timeout -1
spawn ssh -o PubkeyAuthentication=no [email protected]
expect -exact "Password: "
sleep 1
send -- "mypassword\r"
expect -exact ">"
sleep 1
send -- "sh version\r"
expect -exact " >"
sleep 1
send -- "exit\r"
expect {\$\s*} { interact }

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
V
vetash, 2018-06-16
@vetash

Try to expect a console prompt for a pattern, not an exact match.
For MikroTik I use this:

expect "*@*]*>"
and remove sleep.
For example:
#!/usr/bin/expect -f
set timeout -1
spawn ssh -o PubkeyAuthentication=no [email protected]
expect "Password: "
send "mypassword\r"
expect "*>"
send "sh version\r"
expect "*>"
send "exit\r"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question