BELOW SOLUTION負け接続:: SSH :: Perlの
我々は、CSVにデータを抽出し、別のサーバにアップロードして、他のサーバとのコールに接続する必要があるETLシステムを持っていますmemcacheにcsvをロードするためのJava jar。私はこれのすべてのステップを実行できるスクリプトを持っているが、最終ステップのためにSSH接続を失う。リモートマシンのプロセスは続行され、完了します。
Net :: SSH :: Perlを使用しています。短時間実行した後、「接続に失敗しました:ピアによって接続がリセットされました」というエラーが表示されます。私はこれにスクリプトを煮詰めて、結果を複製しました:
localhost: Reading configuration data /home/user/.ssh/config
localhost: Reading configuration data /etc/ssh_config
localhost: Connecting to sshost, port 22.
localhost: Remote protocol version 2.0, remote software version OpenSSH_4.3
localhost: Net::SSH::Perl Version 1.34, protocol version 2.0.
localhost: No compat match: OpenSSH_4.3.
localhost: Connection established.
localhost: Sent key-exchange init (KEXINIT), wait response.
localhost: Algorithms, c->s: 3des-cbc hmac-sha1 none
localhost: Algorithms, s->c: 3des-cbc hmac-sha1 none
localhost: Entering Diffie-Hellman Group 1 key exchange.
localhost: Sent DH public key, waiting for reply.
localhost: Received host key, type 'ssh-dss'.
localhost: Host 'sshost' is known and matches the host key.
localhost: Computing shared secret key.
localhost: Verifying server signature.
localhost: Waiting for NEWKEYS message.
localhost: Send NEWKEYS.
localhost: Enabling encryption/MAC/compression.
localhost: Sending request for user-authentication service.
localhost: Service accepted: ssh-userauth.
localhost: Trying empty user-authentication request.
localhost: Authentication methods that can continue: publickey,gssapi-with-mic.
localhost: Next method to try is publickey.
localhost: Trying pubkey authentication with key file '/path/to/key.rsa'
localhost: Login completed, opening dummy shell channel.
localhost: channel 0: new [client-session]
localhost: Requesting channel_open for channel 0.
localhost: channel 0: open confirm rwindow 0 rmax 32768
localhost: Got channel open confirmation, requesting shell.
localhost: Requesting service shell on channel 0.
localhost: channel 1: new [client-session]
localhost: Requesting channel_open for channel 1.
localhost: Entering interactive session.
localhost: Sending command: cd /usr/local/loader; java -Xms4096m -Xmx4096m -DetlDate=20120427 -DmemcacheHosts=host1,host2 -cp etl-0.1-SNAPSHOT.jar com.nnn.platform.service.etl
localhost: Sending command: cd /usr/local/loader; java -Xms4096m -Xmx4096m -DetlDate=20120427 -DmemcacheHosts=host1,host2 -cp etl-0.1-SNAPSHOT.jar com.nnn.platform.service.etl
localhost: Requesting service exec on channel 1.
localhost: channel 1: open confirm rwindow 0 rmax 32768
jarファイルの出力はSTDERRに出力され、私はそれが返さ参照:
は#!/usr/bin/perl
use strict;
use Net::SSH::Perl;
use Log::Log4perl;
my ($stdout, $stderr, $exit, $ssh);
$ssh = Net::SSH::Perl->new('sshost',
identity_files => ['/path/to/key.rsa'],
protocol => 2,
debug => 1);
$ssh->login('user');
my $cmd = "java -Xms4096m -Xmx4096m -DetlDate=20120427 -DmemcacheHosts=host1,host2 -cp etl-0.1-SNAPSHOT.jar com.nnn.platform.service.etl";
$ssh->register_handler("stdout", sub {
my($channel, $buffer) = @_;
print "STDOUT: ", $buffer->bytes;
});
$ssh->register_handler("stderr", sub {
my($channel, $buffer) = @_;
print "STDERR: ", $buffer->bytes;
});
$ssh->cmd("cd /usr/local/loader; $cmd");
私が取得SSHのデバッグ情報です。 9秒後に停止し、最終的にピアエラーによって接続がリセットされます。 STDERRハンドラーが期待どおりに動作しています。
Net :: SSH :: Perlの処理に問題があるかどうかはわかりませんが、STDERRなどで実行したり戻ったりするのにしばらく時間がかかります。私はNet :: SSH2に切り替えることを検討してきましたが、完全な機能を備えたライブラリのように思えますが、なぜこれが失敗するのかを知りたいのです。
問題
SOLUTIONは出力のみSTDERRに行くとありました。コマンドを編集して2>&1
を追加し、STDERRをSTDOUTにリダイレクトして、突然すべてが期待通りに機能しました。