Hi guys,

I was trying to use Expect.pm but it was just too hard for me to capture remote machine's output via below..

#!/usr/bin/perl

use warnings;
use strict;

use Expect;

my $exp = new Expect;
my $password = 'abc123';
my $user = 'userX';
my $host = '10.3.1.2';

my $login =
     "/usr/bin/ssh [EMAIL PROTECTED]";

$exp->spawn($login)
        or die
           "Can't login to $host as $user: $!\n";

## Enables internal debugging
$exp->exp_internal( 1 );

$exp->log_file("./log_this.txt");

$exp->expect(5, '-re', '(RSA)');
my @matchlist = $exp->matchlist;

$exp->send("yes\n")
    if (  ( $exp->matchlist)[0] );

$exp->expect(5, "password: ");
$exp->send("$password\n");

#my @err = $exp->send("cat /etc/passwd");
#print "$_\n" for @err;

$exp->send("exit\n");
$exp->log_file(undef);

I thought this would capture the output of cat into log file but it does not. I also thought perhaps I can direclty capture it into the array(I have commented them out) but I could not...
can someone lead me to the right path?

thank you.



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to