【问题标题】:installing Net/SSH/Perl.pm安装 Net/SSH/Perl.pm
【发布时间】:2017-02-22 05:53:04
【问题描述】:

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

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

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

有人可以帮助我吗?我试过CPANppmCPAN 说它找不到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.

【问题讨论】:

标签: perl ssh perl-module net-ssh


【解决方案1】:

你可以试试这个:

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

区分大小写。

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

【讨论】:

  • 安装一直挂在随机的“抓取”点。在他们花费大量时间的时候,我做了“ctrl+c”。安装将继续并最终完成。我试着做“cpanm Net::SSH::Perl”,它说“-bash: cpanm: command not found”。谢谢
  • 我想是这样的,但为什么它会挂在一些抓取上?它会坐在一个取物上 10 多分钟。
【解决方案2】:

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

【讨论】:

  • +1 代表所有::SSH 中的正确一个。 Perl 有很多工具,很多相似,很难知道哪个有什么用。
【解决方案3】:

为什么要使用 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).

【讨论】:

    【解决方案4】:

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

    【讨论】:

      【解决方案5】:
      perl -MCPAN -e 'install Net::SSH::Perl'
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-01-22
        • 2020-08-07
        • 1970-01-01
        • 2016-04-30
        • 1970-01-01
        • 2016-09-13
        • 2012-07-04
        • 1970-01-01
        相关资源
        最近更新 更多