Subject: Re: SSH client is not reading full data if executed command generates big output

Re: SSH client is not reading full data if executed command generates big output

From: Subrata Dasgupta <>
Date: 29 Oct 2018 12:23:09 -0000

Hi Peter,Thanks a lot for beautiful explanation.My intention is to run several commands on a small router like device. The device provide a restricted environment and allows user to run only specific set of commands. Some commands may also have sub-commands, for an example until and unless &#39;enable&#39; command is executed user are not allowed to execute few commands. One more example of sub-command is , until and unless &quot;configure terminal&quot; command is executed users are not allowed to run any configuration related commands. So I need to retain the state otherwise I can not execute some commands.I do not fully understand the difference between session and channel. If possible please explain a bit.Is it possible to use &quot;libssh2_channel_exec&quot; in the scenario explained above (means in sub-command case) ? If yes please let me know how.Does &quot;libssh2_channel_exec&quot; is able to provide all the data if command output is very big ?ThanksSubrataFrom: Peter Stuge &lt;;Sen
t: Mon, 29 Oct 2018 02:24:07To: libssh2-devel_at_cool.haxx.seSubject: Re: SSH client is not reading full data if executed command generates big outputSubrata Dasgupta wrote:&gt; My intention is to run multiple commands sequentially over ssh and&gt; get the output.It seems &amp;quot;libssh2_channel_exec&amp;quot; function&gt; can only execute a single command over a session or channel. &nbsp;So&gt; this option will not serve my purpose because commands may have&gt; some sub-commands. &nbsp;So I need to retain the session or channel to&gt; execute those sub-commands. &nbsp;Please let me know if my&gt; understanding is wrong and kindly let me know how to execute&gt; multiple commands and sub-commands over libssh2_channel_exec.Your understanding is correct; libssh2_channel_exec() only everexecutes one command, but you can call it many times within onesession.That allows you to take advantage of well-defined fit-for-purposebehavior and interactions between your client and the server. Thisway, your software has some
chance to control the processes on theserver side.&gt; It seems only &amp;quot;libssh2_channel_shell&amp;quot; function can serve&gt; my purpose because I can execute multiple commands on a established&gt; channel / session. &nbsp;Please let me know if I am wrong.A shell channel is not needed to execute multiple commands in onesession, only to execute multiple commands in one *channel*. Studythe difference to see what is actually required in your case.&gt; It also seems from the different ssh tutorials from net that&gt; non-interactive session may serve my purpose because there is no&gt; pty associated with the channel. &nbsp;So I have tried to comment out&gt; the &amp;quot;libssh2_channel_request_pty&amp;quot; call ,&nbsp;but unfortunately!&gt; result is the same(server do not send all data). &nbsp;What could be&gt; the reason of such problem and how to fix it if possible ?One reason could be that the software you are executing on the serversimply is not written to support both interactive and programmed us
e.You can&#39;t fix that in the client. There can be other reasons, you&#39;llhave to study the particular server software you want to support indetail.&gt; Lastly is there anyway to get all output data of commands or&gt; sub-commands without using terminal emulation ??Please clarify what you mean by &quot;sub-commands&quot; ?In general, if the software you want to execute on the server doesnot explicitly support programmed use (and this is likely the case)then your only option is to write a software that simulates interactiveuse, which neccessarily requires terminal emulation to handle everythingthat the server software outputs, as well as everything that yoursimulator requires to output.Shells are human interfaces, not programming interfaces, making them apoor choice for automation. Sometimes there is may be no other way,but it always requires a lot of (I think wasted) effort. Try to solvethe problem another way if possible.//Peter_______________________________________________libssh2-devel https://cool.ha

Received on 2018-10-29