Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Custom prompts for Net::Appliance::Session

by edimusrex (Monk)
on Sep 14, 2017 at 16:20 UTC ( #1199409=perlquestion: print w/replies, xml ) Need Help??

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

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:

So I've created the following prompt file containing :
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 [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/ 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/ 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/ 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/ line 58 Net::Appliance::Session::Transport::connect('Net::Appliance::S +ession=HASH(0x31d6d30)', 'cisco', 'uzf1IgENudObn759sJ9U') called at . +/ 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/ 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 (Bishop) on Sep 15, 2017 at 05:05 UTC

    G'day edimusrex,

    I've never used any of these modules; however, as your question has been sitting there for over 12 hours without a reply, I thought I'd have a look.

    In Net::CLI::Interact::Phrasebook, under the PHRASEBOOK FORMAT section, it has:

    "Try to make the Prompt as specific as possible, including line-end anchors."

    All the examples show that anchor. Here's the first two match examples:

    match /\(config[^)]*\)# ?$/ match /> ?$/

    And one further down is very close to your password prompt:

    match /[Pp]assword: ?$/

    So instead of

    match /User Name/ match /Password/

    maybe try

    match /User Name: ?$/ match /Password: ?$/

    You might also want to scrutinise your expected prompts for case and whitespace. For instance, perhaps this would work better for the username prompt:

    match /[Uu]ser\s*[Nn]ame:\s*?$/

    — Ken

      After implementing those suggested changes I still get the same error as described above

        I've front-paged your post to give it a bit more exposure: perhaps another monk can provide more assistance. I'm unable to help you further with this, myself.

        — Ken

      Thank you for the reply. I will try that and see if I have any luck.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1199409]
Approved by Corion
Front-paged by kcott
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2021-09-20 09:06 GMT
Find Nodes?
    Voting Booth?

    No recent polls found