Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Expect::Simple help

by sunadmn (Curate)
on Dec 02, 2005 at 17:33 UTC ( [id://513658]=perlquestion: print w/replies, xml ) Need Help??

sunadmn has asked for the wisdom of the Perl Monks concerning the following question:

Hey all I am having some trouble with Expect::Simple and need to get some advice or direction from you all on what I am doing wrong. I am trying to use this module to log into a remote Layer4 load balancer and roll device (servers) in and out of production, but for some reason I am not getting what I want right now below in my code thus far and what errors I am seeing.

Code:
#!/usr/bin/perl -Tw # This is a wrapper script that will use Expect # to telnet to the VIP changer for PHX and roll # in and out of prod for service reasons use strict; use Expect::Simple; my $obj = new Expect::Simple { Cmd => "telnet my.host.com verbose=1", Prompt => 'Enter Password', DisconnectCmd => 'quit', Verbose => 0, Debug => 0, Timeout => 100 }; $obj->send( my $cmd ); print $obj->before; print $obj->after; print $obj->match_str, "\n"; print $obj->match_idx, "\n"; print $obj->error_expect; print $obj->error; my $expect_object = $obj->expect_handle;

Here is what I get in error:

Expect::Simple: Expect::Simple: couldn't find prompt at ./vipPHX.cgi line 11 at ./vipPHX.cgi line 11 print() on closed filehandle GEN0 at /opt/HWPerl/lib/perl5/5.8.0/sun4- +solaris/IO/Handle.pm line 395. print() on closed filehandle GEN0 at /opt/HWPerl/lib/perl5/5.8.0/sun4- +solaris/IO/Handle.pm line 395.
I am lost and do not know where to go from here, does anyone have a beeter example of using this module??

Thanks all
SUNADMN
USE PERL

Replies are listed 'Best First'.
Re: Expect::Simple help
by TedYoung (Deacon) on Dec 02, 2005 at 21:46 UTC

    Well, in your code you are looking for "Password" but your telnet output is "password". I have never used this module, but in general, I look for "assword" when using expect. Aside from being a little funny, it works regardless of the case of the program you are using. Also, just a quick review of the module docs shows that Promt accepts regexes:

    Prompt => [ -re => '[pP]assword' ],

    Ted Young

    ($$<<$$=>$$<=>$$<=$$>>$$) always returns 1. :-)
      Hmm well for some reason this thing just will not match on the regex.See below the exact output from the telnet session:

      [root@www1 stephen] 6# telnet myhost.net Trying x.x.x.x... Connected to myhost.net. Escape character is '^]'. Enter password: telnet> quit

      And now my regex for the prompt is written like so:
      Prompt => [ -re => '[eE]nter\s+' ],

      I have no idea why I am not getting a match here now still. Any thoughts on this one?
      SUNADMN
      USE PERL
Re: Expect::Simple help
by BMaximus (Chaplain) on Dec 02, 2005 at 17:50 UTC
    My guess is that its failing to find the prompt you're asking it to find. Seems like the module is very specific as to how it finds those prompts so it can send commands. Take a look at the prompt you want the module to find and see if it has a ":" at the end or a new line (carrage return?) and then the ":" asking for the password.

    I've never used Expect::Simple so I'm not sure if I'm right or not. It's a WAG at best. Hope it helps.

    BMaximus
      Well this is what my telnet session actually returns for the prompt:
      Trying my.ip.address... Connected to myhost.net. Escape character is '^]'. Enter password:
      SUNADMN
      USE PERL

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://513658]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2024-03-28 21:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found