tuckito has asked for the wisdom of the Perl Monks concerning the following question:
Hello lovers of the great perl,
I have a problem with Net::OpenSSH which I don't quite understand.
My code calls a find command on a remote machine where I'm not able to run perl on so I just grab some information and process it somewhere else.
My problem is that capture2() does return undef in stdout when the result of the executed cli command starts with "00" (from my understanding).
That's the relevant output from debug where the cli command returns "00 , 99":$find = "find $args->{'path'}/ -name '$args->{'foo'}.*' -newer ~/start +.txt ! -newer ~/end.txt | xargs grep -vh 'H\\|T' | awk -F, '{ if( \$1 + !~ /\\// & & \$1 >= $args->{'start'} && \$1 < $args->{'end'}){"; for (my $i = 1; $i <= $indices; $i++){ $find .= "if(\$$args->{'index'.$i} ~ /^[0-9]+\$/ && \$$args->{'ind +ex'.$i} >= $args->{'min'.$i} && \$$args->{'index'.$i} <= $args->{'max +'.$i} ){ print \$$args->{'index'.$i} }"; } $find .= "}}' | sort | uniq -c | awk '{print \$2,\",\",\$1}'"; ($edr,$stderr) = $args->{'ssh'}->capture2($find); if($stderr){ print $stderr;} @edr = split /\n/, $edr;
This debug output shows a working example:# io3 mloop, cin: 0, cout: 1, cerr: 0 # io3 fast, cin: 0, cout: 1, cerr: 0 # stdout, bytes read: 8 at offset 0 #> 30 30 20 2c 20 39 39 0a + | 00 , 99. # io3 fast, cin: 0, cout: 1, cerr: 0 # stdout, bytes read: 0 at offset 8 # leaving _io3() # _waitpid(22920) => pid: 22920, rc: Use of uninitialized value $edr in split at /home/bo/scripts/test.pl l +ine 338.
The cli sommand returns "990102 , 20462" and the script runs fine.# io3 mloop, cin: 0, cout: 1, cerr: 1 # io3 fast, cin: 0, cout: 1, cerr: 1 # stdout, bytes read: 15 at offset 0 #> 39 39 30 31 30 32 20 2c 20 32 30 34 36 32 0a + | 990102 , 20462. # io3 fast, cin: 0, cout: 1, cerr: 1 # stdout, bytes read: 0 at offset 15 # stderr, bytes read: 0 # leaving _io3() # _waitpid(22922) => pid: 22922, rc:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Confused with Net::OpenSSH - capture2()?
by salva (Canon) on Feb 04, 2016 at 10:06 UTC | |
by tuckito (Initiate) on Feb 04, 2016 at 12:43 UTC |