4

我对使用 perl 编写脚本相当陌生。我正在尝试 ssh 进入服务器并执行一些命令。我必须提供用户名和密码。

尝试运行我目前拥有的脚本时(下面列出的代码)。我收到以下错误。

我假设这意味着我需要安装/制作 Net/SSH/Perl.pm,但是,当我按照我在网上找到的说明和教程进行操作时,没有一个有效。

有人可以帮助我吗?我试过CPANand ppmCPAN说它找不到net::ssh::perl该字符串或该字符串的其他变体。ppm甚至不会运行,我在我的 perl 目录中看不到它。任何帮助是极大的赞赏!


// The code
#!/usr/bin/perl
use Net::SSH::Perl;

$uName = "username";
$pWord = "password";

$unitIp = $ARGV[0];

my $ssh = Net::SSH::Perl->new($unitIp, 35903);
$ssh->login($uName, $pWord);
my $out = $ssh->cmd("java -version");
print $out;

// the error that is returned
Can't locate Net/SSH/Perl.pm in @INC (@INC contains: /usr/lib/perl5/5.8.5/i386-linux-thread-multi /usr/lib/perl5/5.8.5 /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.4/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.3/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.2/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.1/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.5 /usr/lib/perl5/site_perl/5.8.4 /usr/lib/perl5/site_perl/5.8.3 /usr/lib/perl5/site_perl/5.8.2 /usr/lib/perl5/site_perl/5.8.1 /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.4/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.3/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.2/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.1/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.5 /usr/lib/perl5/vendor_perl/5.8.4 /usr/lib/perl5/vendor_perl/5.8.3 /usr/lib/perl5/vendor_perl/5.8.2 /usr/lib/perl5/vendor_perl/5.8.1 /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl .) at needsAName.pl line 31.
BEGIN failed--compilation aborted at needsAName.pl line 31.
4

5 回答 5

7

你可以试试这个:

curl -L http://cpanmin.us | perl - --sudo App::cpanminus
cpanm Net::SSH::Perl

区分大小写。

说明:第一行将安装“cpanm” - 恕我直言,安装模块的最简单方法是什么
第二行将安装模块 Net::SSH::Perl

于 2011-05-09T16:28:20.813 回答
2

而不是Net::SSH::Perl尝试使用Net::SSH2或者如果您在 Unix/Linux 环境中Net::OpenSSH。它们更容易安装!

于 2011-05-16T09:53:00.557 回答
1

为什么要使用Net::OpenSSH而不是其他 perl ssh?这是我通过以下方式安装后发现的cpanm

Net::OpenSSH 与 Net::SSH::.* 模块

   Why should you use Net::OpenSSH instead of any of the other Perl SSH
   clients available?

   Well, this is the perldoc writters (biased) opinion:

   Net::SSH::Perl is not well maintained nowadays (update: a new
   maintainer has stepped in so this situation could change!!!), requires
   a bunch of modules (some of them very difficult to install) to be
   acceptably efficient and has an API that is limited in some ways.

   Net::SSH2 is much better than Net::SSH::Perl, but not completely stable
   yet. It can be very difficult to install on some specific operative
   systems and its API is also limited, in the same way as Net::SSH::Perl.

   Using Net::SSH::Expect, in general, is a bad idea. Handling interaction
   with a shell via Expect in a generic way just can not be reliably done.

   Net::SSH is just a wrapper around any SSH binary commands available on
   the machine. It can be very slow as they establish a new SSH connection
   for every operation performed.

   In comparison, Net::OpenSSH is a pure perl module that doesn't have any
   mandatory dependencies (obviously, besides requiring OpenSSH binaries).
于 2012-10-30T14:22:57.610 回答
0

只需在终端上输入 cpan 然后输入: force install Net::SSH::Perl

于 2013-08-12T22:09:42.490 回答
0
perl -MCPAN -e 'install Net::SSH::Perl'
于 2017-02-21T21:53:04.587 回答