2014-12-17 3 views
1

Net :: SSH :: Perl 모듈을 사용하여 원격 시스템에 ssh를 수행하고 싶습니다. ssh 명령을 사용하여 명령 행에서 원격으로 시스템에 로그인 할 수 있지만 펄 script.Can 사람이Net :: SSH :: Perl을 사용하여 원격 시스템에 로그인

내 코드를 도와 것은 :

$user = 'smetest';$pass = 'smetest'; 
print "user is ".$user." password is ".$pass."\n"; 
print "Connecting to the Relay host " . $relayteaddress . ".\n"; 
$sshrelay = Net::SSH::Perl->new($relayteaddress, protocol => '2,1', debug => 1); 
print "logging in to Relay $relayteaddress ...\n"; 
$sshrelay->login($user, $pass) || die "ssh login didn't work\n"; 
print "logged into relay\n"; 

출력 및 디버그 메시지 : 나는 현재 SSH를 받고 문제가 있어요

user is smetest password is smetest 
Connecting to the Relay host 192.168.2.175. 
W10: Reading configuration data /home/systest/.ssh/config 
W10: Reading configuration data /etc/ssh_config 
W10: Connecting to 192.168.2.175, port 22. 
W10: Remote protocol version 2.0, remote software version OpenSSH_6.4 
W10: Net::SSH::Perl Version 1.34, protocol version 2.0. 
.10: No compat match: OpenSSH_6.4 
W10: Connection established. 
logging in to Relay 192.168.2.175 ... 
W10: Sent key-exchange init (KEXINIT), wait response. 
W10: Algorithms, c->s: 3des-cbc hmac-sha1 none 
W10: Algorithms, s->c: 3des-cbc hmac-sha1 none 
W10: Entering Diffie-Hellman Group 1 key exchange. 
W10: Sent DH public key, waiting for reply. 
Key class 'Net::SSH::Perl::Key::RSA' is unsupported: Cannot find current script 'CONDOR_PERF_BAND_ISM2450_80211BGN_CHANNEL_11_ACTIVE_UDP_TX_LGI_AP20' at /usr/share/perl5/FindBin.pm line 205 
BEGIN failed--compilation aborted at /usr/share/perl5/FindBin.pm line 205, <GEN26> line 1. 
Compilation failed in require at /usr/share/perl5/vendor_perl/Crypt/RSA.pm line 13, <GEN26> line 1. 
BEGIN failed--compilation aborted at /usr/share/perl5/vendor_perl/Crypt/RSA.pm line 13, <GEN26> line 1. 
Compilation failed in require at /usr/share/perl5/vendor_perl/Net/SSH/Perl/Key/RSA.pm line 14, <GEN26> line 1. 
BEGIN failed--compilation aborted at /usr/share/perl5/vendor_perl/Net/SSH/Perl/Key/RSA.pm line 14, <GEN26> line 1. 
Compilation failed in require at (eval 45) line 1, <GEN26> line 1. 
BEGIN failed--compilation aborted at (eval 45) line 1, <GEN26> line 1. 
+2

FindBin은 실행중인 스크립트를 찾기 위해 (근처 디렉토리의 관련 파일을 찾기 위해) 사용됩니다. 'chdir'이 사용되면 실패 할 수 있습니다. – ikegami

+0

chdir을 사용하지 않았기 때문에 그 파일을 찾을 수 없다고 말하는 이유를 모르겠습니다. – alily

+0

스크립트의 이름이 실제로 'CONDOR_PERF_BAND_ISM2450_80211BGN_CHANNEL_11_ACTIVE_UDP_TX_LGI_AP20'입니까? – ikegami

답변

1

것은 인터넷을 사용하여 작업 할 수 :: SSH :: Perl 그러나 나는 t를 만들었다. 그의 스크립트는 잠시 동안 간단히 해결됩니다. 비슷한 상황에서 누구에게 도움이되기를 바랍니다. 분명히 명령은 연결되면 여러 명령을 발행하는 데 사용되는 데모입니다.

use strict; 
    use warnings; 
    use Expect; 

    $exp= Expect->spawn("ssh $host -l $user"); 

    $exp->expect($timeout,"Password:"); 
    $exp->send("$pass\r"); 

    $exp->expect($timeout,-re,'>'); 
    $exp->send("ls -l\r"); 

    $exp->expect($timeout,-re,'>'); 
    $exp->send("mkdir aDir\r"); 

    $exp->expect($timeout,-re,'>'); 
    $exp->send("chmod 777 aDir\r"); 

    $exp->expect($timeout,-re,'>'); 
    $exp->send("exit\r"); 
관련 문제