Expect module - need some help...

Discussion in 'Perl Misc' started by tudmuf2b@onebox.com, Mar 16, 2005.

  1. Guest

    Hey folks...

    I am playing around with the Expect module and have been looking at the
    docs, but am confused as to why my code does not send the "ls" to the
    remote host.

    My code is below (along with the trace). The remote host does not have
    NIS running so hence the warnings...

    So I am trying to ssh to "moocow" and the just run and "ls" and get
    that output but for whatever reason it just doesn't give me the ls
    output. I do see that I get into expect part (where I am expecting to
    get the $ prompt), but when I do a print "ls\n", it doesn't work. I've
    tried this with the $exp->send("ls\r") but it doesn't work.

    any ideas, as this is probably a simple issue???

    #!/usr/local/bin/perl

    use strict;
    use warnings;
    use Expect;

    $Expect::Exp_Internal = 1;
    #$Expect::Debug = 3;

    my $exp = new Expect;

    $exp->spawn("ssh moocow") || warn "Cannot spawn ssh: $!\n";

    if ( $exp->expect(12,"\$ ") ) {
    print "I made it in here\n";
    print $exp "ls\n";
    }

    print "\n";

    =========================

    Spawned 'ssh moocow'
    spawn id(3)
    Pid: 10919
    Tty: /dev/pts/22
    Expect::spawn('Expect=GLOB(0x9eb5f38)', 'ssh moocow') called at
    ../test
    ..expect.module.pl line 17
    Starting EXPECT pattern matching...
    Expect::expect('Expect=GLOB(0x9eb5f38)', 12, '$ ') called at
    ../test.ex
    pect.module.pl line 19
    spawn id(3): list of patterns:
    #1: -ex `$ '

    spawn id(3): Does `'
    match:
    pattern #1: -ex `$ '? No.

    Waiting for new data (12 seconds)...
    Warning: Remote host denied X11 forwarding, perhaps xauth program could
    not be
    run on the server side.

    spawn id(3): Does `Warning: Remote host denied X11 forwarding, perhaps
    xauth p
    rogram could not be run on the server side.\

    r\r\n'
    match:
    pattern #1: -ex `$ '? No.

    Waiting for new data (12 seconds)...
    ypwhich: can't get local yp domain: Local domain name not set

    spawn id(3): Does `Warning: Remote host denied X11 forwarding, perhaps
    xauth p
    rogram could not be run on the server side.\r\r\nypwhich: can\'t get
    local yp
    domain: Local domain name not set\r\n'
    match:
    pattern #1: -ex `$ '? No.

    Waiting for new data (12 seconds)...
    moocow 1$
    spawn id(3): Does `Warning: Remote host denied X11 forwarding, perhaps
    xauth p
    rogram could not be run on the server side.\r\r\nypwhich: can\'t get
    local yp
    domain: Local domain name not set\r\nmoocow 1$ '
    match:
    pattern #1: -ex `$ '? YES!!
    Before match string: `Warning: Remote host denied X11 forwarding,
    perhaps
    xauth program could not be run on the server side.\r\r\nypwhich: can\'t
    get lo
    cal yp domain: Local domain name not set\r\nmoocow 1'
    Match string: `$ '
    After match string: `'
    Matchlist: ()
    Returning from expect successfully.
    I made it in here
     
    , Mar 16, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. z0mb1e_fr
    Replies:
    2
    Views:
    748
    z0mb1e_fr
    Dec 3, 2003
  2. =?Utf-8?B?cGFhcGEyMQ==?=

    udate doesn't work as expect need help

    =?Utf-8?B?cGFhcGEyMQ==?=, Jan 9, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    368
    Henrique Mello
    Jan 9, 2006
  3. Maric Michaud
    Replies:
    0
    Views:
    7,204
    Maric Michaud
    Jun 24, 2006
  4. Simon Strandgaard

    how to expect eof with expect+pty

    Simon Strandgaard, Dec 20, 2006, in forum: Ruby
    Replies:
    4
    Views:
    366
    Simon Strandgaard
    Dec 20, 2006
  5. Phil
    Replies:
    0
    Views:
    171
Loading...

Share This Page