Answer the question
In order to leave comments, you need to log in
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
Try to expect a console prompt for a pattern, not an exact match.
For MikroTik I use this:
expect "*@*]*>"and remove sleep.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question