edimusrex has asked for the wisdom of the Perl Monks concerning the following question:
Before I begin I have posted a similar question to the following https://serverfault.com/questions/873672/custom-prompt-using-netappliancesession
So what I am trying to do is create a custom login prompt for my cisco smart switch. The prompt expected for the username/password is
User Name: Password:
prompt username match /User Name/ prompt password match /Password/
My script code looks like this :
#!/usr/bin/perl use warnings; use strict; use Net::Appliance::Session; my $host = '<my_host>'; my $user = '<my_user>'; my $pass = '<my_pass>'; my $session = Net::Appliance::Session->new({ add_library => '/home/edunn/switch', personality => 'custom', transport => 'SSH', host => $host, connect_options => { opts => [ '-q', ], }, }); $session->set_global_log_at('debug'); $session->connect($user,$pass ) or die "Cannot Connect! : $!"; my @output = $session->cmd('show version'); $session->close; print join("\n",@output);
When I run the script I get the following error
[0.001442] p finding prompt [0.006910] t creating Net::Telnet wrapper for ssh [0.007164] t command expands to: ssh -o StrictHostKeyChecking=n +o -o UserKnownHostsFile=/dev/null -o CheckHostIP=no -q 192.168.2.17 [1.349082] d SEEN: [1.364935] p reading phrasebook /home/edunn/switch/custom/login [1.365581] p storing prompt username [1.366753] p storing prompt password [1.367592] p nope, doesn't (yet) match password [1.367821] p nope, doesn't (yet) match username [1.368008] p no match so far, more data? [1.368295] d SEEN: [1.368446] p nope, doesn't (yet) match password [1.368690] p nope, doesn't (yet) match username [1.368877] p no match so far, more data? [1.384701] d SEEN: User Name: [1.384963] p nope, doesn't (yet) match password [1.385179] p hit, matches prompt username [1.385931] p prompt has been set to (?-xism:User Name) unknown prompt [prompt] at /usr/share/perl5/vendor_perl/Net/CLI/Intera +ct/Phrasebook.pm line 53 Net::CLI::Interact::Phrasebook::prompt('Net::CLI::Interact::Ph +rasebook=HASH(0x3665390)', 'prompt') called at /usr/share/perl5/vendo +r_perl/Net/CLI/Interact/Role/Prompt.pm line 48 Net::CLI::Interact::Role::Prompt::prompt_looks_like('Net::CLI: +:Interact=HASH(0x329dc78)', 'prompt') called at /usr/lib64/perl5/vend +or_perl/Moose/Meta/Method/Delegation.pm line 108 Net::Appliance::Session::prompt_looks_like('Net::Appliance::Se +ssion=HASH(0x31d6d30)', 'prompt') called at /usr/share/perl5/vendor_p +erl/Net/Appliance/Session/Transport.pm line 58 Net::Appliance::Session::Transport::connect('Net::Appliance::S +ession=HASH(0x31d6d30)', 'cisco', 'uzf1IgENudObn759sJ9U') called at . +/switch.pl line 21
If I am looking at this correctly it appears to be successfully identifying the User Name and the Password prompts but dies at unknown prompt prompt at /usr/share/perl5/vendor_perl/Net/CLI/Interact/Phrasebook.pm line 53. No sure what the expected value prompt is or where it is coming from.
As always, any and all help will be greatly appreciated
**** UPDATE ****
I ended up updating the firmware to the switch which added the ability for user authenticated ssh so I no longer have the need to look for quirky prompts and can now use the Net::Appliance::Session module without a hitch. Thank you all for suggestions.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Custom prompts for Net::Appliance::Session
by kcott (Archbishop) on Sep 15, 2017 at 05:05 UTC | |
by edimusrex (Monk) on Sep 15, 2017 at 14:52 UTC | |
by kcott (Archbishop) on Sep 16, 2017 at 03:31 UTC | |
by edimusrex (Monk) on Sep 15, 2017 at 14:33 UTC |