There are some server and client side Interval settings for the timeout. See setting ssh timeouts or google for "ssh timeouts".

If those settings don't do it, you might try the various methods available in perldoc Net::SSH2::Channel. For instance:

Setting blocking to 1, or instead of $chan2->close; you might try $chan2->send_eof, or ask for a pty with $chan2->pty

There is a problem with a Net::SSH2 connection compared to a c ssh utility connection, in that the c utility will automatically detach itself when you try to run a background process.... it shows up in my pid list designated as as no_tty ? But with Net::SSH2, you need to manually do it. Thats my incomplete understanding.

There is some updated example code for exec'ing a program into the background at A little demo for Net::SSH2, and you may have to do that as a last resort.

# to run a remote command in the background # you need to semi-daemonize it by redirecting it's filehandles my $chan3 = $ssh2->channel(); $chan3->blocking(1); $chan3->exec("nohup /home/zentara/perlplay/net/zzsleep > foo.out 2> fo +o.err < /dev/null &"); $chan3->send_eof;
But for your particular problem, it sounds like you are closing $chan2, before the data can be completely transferred, and the randomness of the amount of return you get, is just system load variations playing out, while the $chan2->close is executed. Have you tried commenting out $chan2->close; and do a wait_closed or something similar, as described in perldoc Net::SSH2::Channel?

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

In reply to Re: NET::SSH2 Terminates by zentara
in thread NET::SSH2 Terminates by sporkit

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.