tags:

views:

91

answers:

2

In my program I use Expect to run ssh. My program is

$argument="[email protected]";
$exp->spawn("ssh $argument") or die "Cannot spawn ssh to ip $ssh_ip_address\n";

But even if it is not able to spawn ssh it is not printing Cannot spawn ssh to ip $ssh_ip_address. Can you please help me understand why it does give the error message?

A: 

First of all, you used double quotes for your $argument declaration, which means that variables will be interpolated in its contents. @10 will be evaluated to the contents of the array @10. Use single quotes to avoid interpolation.

And remember, always always include use strict; use warnings; at the top of every Perl module, program and script. It will save you from lots of hidden errors and therefore a lot of headache. :)

For anything more, you'll have to post the actual code you're running.

Ether
A: 

Instead of using Expect directly, run either Net::SSH::Expect (which wraps up SSH interaction with Expect) or Net::OpenSSH (whuch doesn't use Expect, and advises against it). Also, always use strict and warnings.

MkV