0

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

$argument="root@10.2.2.2";
$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?

4

2 回答 2

1

首先,您在$argument声明中使用了双引号,这意味着将在其内容中插入变量。@10将被评估为数组的内容@10。使用单引号来避免插值。

请记住,始终始终包含use strict; use warnings;在每个 Perl 模块、程序和脚本的顶部。它将使您免于许多隐藏的错误,因此会让人头疼。:)

除此之外,您必须发布您正在运行的实际代码。

于 2010-07-09T16:14:27.180 回答
1

不要直接使用 Expect,而是运行Net::SSH::Expect(它封装了与 Expect 的 SSH 交互)或Net::OpenSSH(它不使用 Expect,并建议不要使用它)。此外,请始终使用严格和警告。

于 2010-07-09T18:10:47.060 回答