私は成功しNet::SSH::Perl
モジュールをインストールするために管理している場合、私は知らないが、私は次のコードを実行することができるように見えることはできません。Net :: SSH :: Perlを使ってSSHコマンドを実行するには?
my $ssh = Net::SSH::Perl->new($remote_host);
$ssh->login($username, $password);
print "login done", "\n";
my ($out, $err, $exit) = $ssh->cmd($cmd);
print "$out", "\n";
私はログインできていますが、$out
を印刷することはできません。このエラーが発生し続ける:
Use of uninitialized value $out in string at test_ssh.pl line 28.
28行目はprint "$out", "\n";
を指しています。
私はCygwinでこのコードを実行しています。私は今どうすればいい?
EDIT: 私はmy $ssh = Net::SSH::Perl->new($remote_host, options => ["Debug yes"]);
を実行したときに、私は次のようなエラーMSGを得た:
Use of uninitialized value $out in string at test_ssh.pl line 29 (#1)
(W uninitialized) An undefined value was used as if it were already
defined. It was interpreted as a "" or a 0, but maybe it was a mistake.
To suppress this warning assign a defined value to your variables.
To help you figure out what was undefined, perl will try to tell you the
name of the variable (if any) that was undefined. In some cases it cannot
do this, so it also tells you what operation you used the undefined value
in. Note, however, that perl optimizes your program and the operation
displayed in the warning may not necessarily appear literally in your
program. For example, "that $foo" is usually optimized into "that "
. $foo, and the warning will refer to the concatenation (.) operator,
even though there is no . in your program.
EDIT2: ここに私の完全なコード
use strict;
use warnings;
use Net::SSH::Perl;
my $remote_host = '<host ip address>';
my $password = 'pass';
my $username = 'user';
my $cmd = 'copy run tftp:<my own ip address>';
warn "Starting SSH Services:...";
my $ssh = Net::SSH::Perl->new($remote_host, debug => 1);
print "done", "\n";
warn "Starting Login:...";
$ssh->login($username, $password);
print "login done", "\n";
warn "Starting command:...";
#$ssh->cmd($cmd);
#my($stdout, $stderr, $exit) = $ssh->cmd($cmd);
my ($out, $err, $exit) = $ssh->cmd($cmd);
print "$out", "\n";
「印刷 "$アウト" のエラーメッセージがあります、 "\ n"; "ライン:
<Computername>: channel 1: new [client-session]
<Computername>: Requesting channel_open for channel 1.
<Computername>: Entering interactive session.
<Computername>: Channel open failure: 1: reason 4:
Use of uninitialized value $out in string at test_ssh.pl line 29.
LAST編集:私は代わりにネットワークデバイスにSSH経由でログインするネット::アプライアンス::セッションを使用することにしました。 Net :: SSH :: Perlよりも使い方が簡単です。
私の$ sshを=ネット:: SSH :: Perl->新しい($ REMOTE_HOST、オプション=> [ "デバッグはい"])とデバッグをオンにし、印刷前にerrの値を確認してください。わからない場合は、errの値とデバッグ出力を表示してください。 – weismat
"print" $ out "、" \ n ";"です。私はあなたが私に与えたコードを追加した後、同じエラーメッセージ(異なる行番号を除いて同じコード行を参照しています)を得ました。 – Sakura
@weismat:これは、このモジュールのデバッグを有効にする方法ではありません。 – Borodin