|
From: Serge T. <ser...@gm...> - 2018-06-20 09:52:35
|
Thank you Dave,
other modules Net::OpenSSH (Net::OpenSSH2, Net::Appliance::Session)
are very interesting, but not in my case.
The problem is resolving by adding "interactive" at the end of the string:
"$login\@$host", "interactive") to switch ssh in interactive mode.
2018-06-10 4:55 GMT+03:00 Dave Jacoby <jac...@gm...>:
> I'm happy to look at it further later, but seems like Net::OpenSSH (is that
> the module? Going from memory.) is a better choice for this task.
>
> sent from my pocket supercomputer
>
> On Sat, Jun 9, 2018, 10:45 AM Serge Torop <ser...@gm...> wrote:
>>
>> 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
>>
>>
>> ------------------------------------------------------------------------------
>> Check out the vibrant tech community on one of the world's most
>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>> _______________________________________________
>> Expectperl-discuss mailing list
>> Exp...@li...
>> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss
--
Serge P. Torop
|