# perl and p5-Expect



## BostonDriver (Nov 11, 2011)

I'm using perl and p5-Expect in 8.2-Release.


```
#!/usr/bin/perl -w

my $command = "ssh -l $user $router

use Expect;

my $exp = new Expect;

$exp->raw_pty(1);
$exp->spawn($command) or die "Cannot spawn $command: $!\n";

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

#
# NOTHING happens above.  But when I added this bogus line, the password 
# finally is sent.  The rest of the script isn't of much use though
#
exp->expect(1, "Bogus, just time out");
[rest of script]
```

If I change the sending of password to below, the sends fails.


```
$exp->send("$password\n") or die "sending of password failed: $!\n";
```

Given this log in sequence looks identical to every FAQ I've seen via Google, I'm curious what I screwed up?  

I'm using perl-5.12.3, p5-Expect-1.21, p5-IO-Stty-0.03.  Is there a different port I should use vs p5-Expect these days?


----------



## Alt (Nov 12, 2011)

ssh sends "Password:" line to STDERR isnt ?


----------



## BostonDriver (Nov 13, 2011)

Alt said:
			
		

> ssh sends "Password:" line to STDERR isnt ?



Sorry, I'm not sure I understand re "isnt"?  Are you suggesting ssh (OpenSSH) uses STDERR to prompt?  

The script came with some SW I'm asked to port.  It's claimed that this script "always" worked with ssh.  (Perhaps ssh just started using STDERR?)

Anyway, I started playing with p5-Net-OpenSSH, and am thinking about moving the script to us it.  I've never touched perl until now, but it didn't take long to get that module to let me log on to the remote system.  Once I'm more comfortable. I'll make the change to p5-Net-OpenSSH.  But would like to get to the root cause of the initial issue.

Thanks


----------



## Alt (Nov 13, 2011)

Okok.. maybe you can use ssh keys to bypass password?


----------



## BostonDriver (Dec 8, 2011)

I solved this.  I replaced what was original used to login, with the Net::OpenSSH perl module.  Specifically p5-Net-OpenSSH via ports.


----------

