|
From: Serge T. <ser...@gm...> - 2018-06-09 14:45:41
|
Hello all,
I need to manage switches and I'm using the Expect module (usually
NET::SSH::Expect).
*Many* models of switches work properly, except one.
To demonstrate it I'm using simple script:
#!/usr/bin/perl
use strict;
use warnings;
use Expect;
use IO::Stty;
my $login = "user";
my $host = "10.10.10.1";
my $prompt = ">";
my $passwd = "pass123";
my $timeout = 2;
my @command = ("/usr/bin/ssh",
"-o StrictHostKeyChecking=no",
"-o PreferredAuthentications=password",
"-o PubkeyAuthentication=no",
"$login\@$host");
my $exp = new Expect();
$exp = Expect->spawn(@command) or die "Cannot spawn $command[0]: $!\n";
$exp->expect(2,'-re',"Password: ");
$exp->send("$passwd\r");
$exp->expect($timeout,$prompt);
$exp->send("show version\r");
$exp->expect($timeout, $prompt);
The result is:
[user@linuxhost]# ./script
user@10.10.10.1's password:
Welcome to SwitchHost console
Enter username: user
Enter terminal type: vt100
SwitchHost:1:> ^[[62;13R [user@linuxhost]# ;13R^C
This is a escape sequences. The script does not return any results.
If I rty to add interact the command -
$exp->interact();
I have properly result:
[user@linuxhost]# ./script
tsp@10.10.10.1's password:
Welcome to SwitchHost console
Enter username: user
Enter terminal type: vt100
SwitchHost:1:> show version
SwitchNAT 4080
Firmware version: 3.1.3.2.3
S/N: 1C8776550B51
SwitchHost:2:> quit
Successfully exit from SwitchHost console
Everything looks good.
I'm try to change TERM settings of my linux console and different
method (/usr/bin/expect, NET::SSH::Expect etc),
but result the same. Usually scripts freeze after:
^[[62;13R
Also, if I try to connect using /usr/bin/ssh from linux console the
result always *good*,
I don't see the ESC sequences.
My question is: Is it possible to handle this sequences (this is
\x1B\x5B\x33...) or filter it?
Does this switch using only interact mode (in this case how to manage
it with scripts)?
Additional info: I have logged session to file, here is the top:
ESC[3gESC[39mWelcome to SwitchHost console
ESC[39m
ESC[39mEnter username: user^M
ESC[39mEnter terminal type: vt100^M
ESC[39mESC[39mSwitchHost:ESC[39m1:ESC[39m>
[ ... ]
Thank you in advance.
--
Serge P. Torop
|