Andy16 has asked for the wisdom of the Perl Monks concerning the following question:
===== Summary of my perl5 (revision 5 version 10 subversion 0) configuration +: Platform: osname=linux, osvers=2.4.21-297-default, archname=i686-linux-threa +d-multi uname='linux gila 2.4.21-297-default #1 sat jul 23 07:47:39 utc 20 +05 i686 i686 i386 gnulinux ' config_args='-ders -Dcc=gcc -Dusethreads -Duseithreads -Ud_sigsetj +mp -Uinstallusrbinperl -Ulocincpth= -Uloclibpth= -Accflags=-DUSE_SITE +CUSTOMIZE -Duselargefiles -Accflags=-DPRIVLIB_LAST_IN_INC -Dprefix=/N +NM/perl -Dprivlib=/NNM/perl/lib -Darchlib=/NNM/perl/lib -Dsiteprefix= +/NNM/perl/site -Dsitelib=/NNM/perl/site/lib -Dsitearch=/NNM/perl/site +/lib -Dsed=/bin/sed -Duseshrplib -Dcf_by=ActiveState -Dcf_email=suppo +rt@ActiveState.com' ===== package Net::OpenSSH; our $VERSION = '0.60'; =====
use strict; use warnings; use Data::Dumper; use Net::OpenSSH; use Sys::SigAction qw( set_sig_handler sig_alarm timeout_call); use File::Path 'rmtree'; #$Net::OpenSSH::debug = -1; my $sshuser="user"; my $sshpwd="pwd"; my $sshtimeout = 90; # sec for timeout my $workertimeout = 120; my @rawout=(); my $device = $ARGV[0]; my $remoteCmd = $ARGV[1]; my $error; my $ssh; my $path = "./Y.ssh.$$"; my @sshcmds= split(';', $remoteCmd); foreach my $sshcmd (@sshcmds) { rmtree([ $path ]); $ssh = Net::OpenSSH->new( $device, user => $sshuser, passwd => $sshpwd, ctl_dir => $path, master_opts => [-o => "StrictHostKeyChecking=no", -o => "UserK +nownHostsFile=/dev/null"], timeout => $sshtimeout, kill_ssh_on_timeout => 1, strict_mode => 0, master_stderr_discard => 1 # to get rid of login screen ); if ($ssh->error) { $error = $ssh->error; chomp($error); print STDOUT "ERROR-1: " . $error . "\n"; rmtree([ $path ]); exit 1; }; if (timeout_call($workertimeout, sub{ my @cmdout = $ssh->capture({timeout => $sshtimeout, stdin_data + => "\n"}, $sshcmd."\n"); if ($ssh->error) { $error = $ssh->error; chomp($error); print STDOUT "ERROR-2: " . $error . "\n"; rmtree([ $path ]); exit 2; }; push @rawout, @cmdout; } )) { # time out action print STDOUT "ERROR-3: SSH cancled by thread after $workertime +out secs\n"; rmtree([ $path ]); exit 3; }; if ($ssh->error) { $error = $ssh->error; chomp($error); print STDOUT "ERROR-4: SSH: " . $error ."\n"; rmtree([ $path ]); exit 4; }; $ssh->master_exited; } rmtree([ $path ]); foreach (@rawout) { print STDOUT $_; } exit 0;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Net::OpenSSH loosing lines ins reply
by salva (Canon) on Jun 04, 2014 at 08:04 UTC | |
by Andy16 (Acolyte) on Jun 04, 2014 at 11:03 UTC | |
by salva (Canon) on Jun 04, 2014 at 11:10 UTC | |
by Andy16 (Acolyte) on Jun 04, 2014 at 11:53 UTC | |
by salva (Canon) on Jun 04, 2014 at 12:07 UTC | |
by Andy16 (Acolyte) on Jun 04, 2014 at 12:19 UTC | |
|