in reply to Re^14: Net::OpenSSH loosing lines ins reply
in thread Net::OpenSSH loosing lines ins reply

Hi,

stripped it down to that level:
#!perl -w use strict; use warnings; use Data::Dumper; use Net::OpenSSH; my $sshuser="user"; my $sshpwd="pwd"; my $device = $ARGV[0]; my $sshcmd = $ARGV[1]; my $error; my $ssh; my $path = "./Y.ssh"; $ssh = Net::OpenSSH->new( $device, user => $sshuser, passwd => $sshpwd, ctl_dir => $path, master_opts => [-o => "StrictHostKeyChecking=no", -o => "UserKnown +HostsFile=/dev/null"], strict_mode => 0, master_stderr_discard => 1 # to get rid of login screen ); my @cmdout; my @cmdout2; @cmdout2 = $ssh->capture({stdin_data => "\n"}, $sshcmd."\n"); open FILE, "<", "./rawout.txt"; @cmdout = <FILE>; close(FILE); $ssh->master_exited; foreach (@cmdout) { print $_; } exit 0;



YES - program is for testing ONLY
no sense !!

BUT
output misses some lines from time to time!!

Output is FINE if I don't run the capture

back to you - I'm out of ideas now, at least for today

Thanks for help!!

Replies are listed 'Best First'.
Re^16: Net::OpenSSH loosing lines ins reply
by salva (Canon) on Jun 04, 2014 at 17:47 UTC

    Don't call master_exited. Though that would probably not solve anything.

    What is print returning?

    for (@cmdout) { my $bytes = print $_; print STDERR "bytes: $bytes, err: $!\n"; }

    Also, use strace in order to see what is going on at the OS level.

      Hi Salva,

      good ideas, will follow up tomorrow,
      but hard to do - as I have to read the full output line by line every time to find, if there is one missing...
      If I only count the lines - I miss the info.

      grrr...
        Good morning Salva,


        I think you lead us to the correct track... :-)


        open OUT, ">", "./trace.out"; my $line =0; foreach (@cmdout) { $line++; my $bytes = print $line.": ".$_; print OUT "$line: bytes: $bytes, err: $! \n"; } close(OUT);


        IF everything is fine trace looks like this for all lines:
        ... 1880: bytes: 1, err: Inappropriate ioctl for device 1881: bytes: 1, err: Inappropriate ioctl for device 1882: bytes: 1, err: Inappropriate ioctl for device 1883: bytes: 1, err: Inappropriate ioctl for device 1884: bytes: 1, err: Inappropriate ioctl for device ...
        IF it starts to fail:
        ... 1891: bytes: 1, err: Inappropriate ioctl for device 1892: bytes: 1, err: Inappropriate ioctl for device 1893: bytes: , err: Resource temporarily unavailable 1894: bytes: , err: Resource temporarily unavailable 1895: bytes: , err: Resource temporarily unavailable 1896: bytes: , err: Resource temporarily unavailable 1897: bytes: , err: Resource temporarily unavailable ...


        Does this ring a bell?
        update caught it in strace:
        write(1, "07651738\n1313: switchport acce"..., 4096) = 4096 write(1, ": interface Ethernet2/36\n1426: "..., 4096) = 4096 write(1, "ntrusted\n1539: service-policy "..., 4096) = 4096 write(1, "torm-control broadcast level 10."..., 4096) = 4096 write(1, "rol broadcast level 10.00\n1782: "..., 4096) = -1 EAGAIN (Re +source temporarily unavailable) write(1, "t level 10.00\n1894: service-po"..., 4096) = -1 EAGAIN (Re +source temporarily unavailable) write(1, "e-policy type queuing input N7K-"..., 4096) = -1 EAGAIN (Res +ource temporarily unavailable) write(1, "141: channel-group 1305 mode a"..., 4096) = -1 EAGAIN (Res +ource temporarily unavailable) write(1, "storm-control broadcast level 10"..., 4096) = -1 EAGAIN (Res +ource temporarily unavailable)