2011-05-09 156 views
4

我對Perl腳本編程相當陌生。我試圖SSH入服務器並執行一些命令。我必須提供用戶名和密碼。安裝Net/SSH/Perl.pm

當試圖運行我到目前爲止的腳本(下面列出的代碼)。我收到以下錯誤。

我假設這意味着我需要安裝/製作Net/SSH/Perl.pm,但是,當我按照我在網上找到的說明和教程時,沒有任何工作。

有人可以幫助我。我試過CPANppm,CPAN表示找不到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. 
+3

從[堆棧溢出的Perl FAQ](http://stackoverflow.com/questions/tagged/perl?sort=faq):什麼是安裝缺少的Perl模塊最簡單的方法? ](http://stackoverflow.com/questions/65865/whats-the-easiest-way-to-install-a-missing-perl-module) – daxim 2011-05-09 20:38:25

回答

7

你可以試試這個:

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

區分大小寫。

說明: 1號線將安裝「cpanm」 - 什麼是恕我直言安裝模塊
二號線將安裝模塊的Net :: SSH :: Perl的

+0

安裝保持hangi隨機「提取」點。在這段時間裏,我做了「ctrl + c」,當時他們花了很多時間。安裝將繼續並最終完成。我試過做「cpanm Net :: SSH :: Perl」,它說「-bash:cpanm:command not found」。謝謝 – prolink007 2011-05-09 17:00:03

+0

我覺得是這樣,但爲什麼它掛在一些取材?它會坐在一個10分鐘以上。 – prolink007 2011-05-09 17:28:26

+0

嘗試檢查:http://www.cpan.org/modules/INSTALL.html和/或http://search.cpan.org/~miyagawa/App-cpanminus-1.4004/lib/App/cpanminus.pm – jm666 2011-05-09 18:56:26

1

代替Net::SSH::Perl最簡單的方法嘗試使用Net::SSH2或者你在Unix/Linux環境Net::OpenSSH。他們更容易安裝!

+0

+ 1爲所有':: SSH'中的一個。 Perl有很多工具,很多類似,很難知道哪些是有用的。 – 2012-10-30 14:14:54

1

爲什麼要使用Net :: OpenSSH而不是其他perl ssh?這是我發現通過cpanm安裝之後:

的Net :: OpenSSH的Vs的淨:: 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). 
0

只是在終端上鍵入CPAN,然後鍵入:強制安裝的Net :: SSH :: Perl的

0
perl -MCPAN -e 'install Net::SSH::Perl'