Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Net::OpenSSH loosing lines ins reply

by salva (Canon)
on Jun 04, 2014 at 08:04 UTC ( [id://1088588]=note: print w/replies, xml ) Need Help??


in reply to Net::OpenSSH loosing lines ins reply

In order to determine if the problem lays on Net::OpenSSH or on the SSH layer, instead of capturing the output with capture, redirect it to some file:
$index++; $ssh->system({ timeout => $sshtimeout, stdin_data => "\n", stdout_file => "/tmp/stdout_${index}.txt" }, $sshcmd."\n");

Then look into those files, if there is still some missing data, it would mean that the problem is on the SSH layer, probably on the SSH server. Otherwise, the more likely cause of the problem would be some bug on Net::OpenSSH.

It is not uncommon for network equipment to have defective SSH implementations. When that happens, if you are lucky, a firmware update may solve it. Otherwise, you may need to employ some ugly workaround like activating pagination and using Expect to request pages.

Replies are listed 'Best First'.
Re^2: Net::OpenSSH loosing lines ins reply
by Andy16 (Acolyte) on Jun 04, 2014 at 11:03 UTC
    Hi Salva,

    thanks for picking that up!

    I changed the code:
    if (timeout_call($workertimeout, sub{ $ssh->system({ timeout => $sshtimeout, stdin_data => "\n", stdout_file => "/tmp/ssh_del_$$.txt" }, $sshcmd."\n"); open FILE, "<", "/tmp/ssh_del_$$.txt"; my @cmdout = <FILE>; close(FILE); # my @cmdout = $ssh->capture({timeout => $sshtimeout, stdin_da +ta => "\n"}, $sshcmd."\n"); # if ($ssh->error) # { # $error = $ssh->error; # chomp($error); # print STDOUT "ERROR-2: " . $error . "\n"; # rmtree([ $path ]); # exit 2; # }; push @rawout, @cmdout; }


    and tested again.

    Funny:
    I just count the number of lines in the output - and it still differs!
    BUT: the files in /tmp are all the same size!!!

    strange, or?

      That probably means that there are some bug on the server SSH implementation (the other possibility being a bug on the OpenSSH ssh client which is very stable and mature and unlikely to have bugs like that).
      ... and even more fun....

      changed the printing part of the script:

      my $tmpcnt=0; open TWO, ">", "./two.out"; foreach (@rawout) { print "$tmpcnt: ". $_; print TWO "$tmpcnt: ". $_; $tmpcnt++; }


      after running I "tee" stdout to a file and "wc -l" after "tee".
      Sometimes "wc -l" shows a reduced number.
      Then, the tee'ed file also misses a block of lines.
      BUT two.out contains all of them.

      argh!
        Which PerlIO layers are attached to the file handlers?
        use Data::Dumper; my $tmpcnt=0; open TWO, ">", "./two.out"; print STDERR Dumper [PerlIO::get_layers(\*STDOUT)]; print STDERR Dumper [PerlIO::get_layers(\*TWO)]; foreach (@rawout) { print "$tmpcnt: ". $_; print TWO "$tmpcnt: ". $_; $tmpcnt++; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1088588]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (2)
As of 2024-04-26 03:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found