Expect module - need some help...


T

tudmuf2b

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
 
Ad

Advertisements


Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top