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 'enable' command is executed user are not allowed to execute few commands. One more example of sub-command is , until and unless "configure terminal" 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 "libssh2_channel_exec" in the scenario explained above (means in sub-command case) ? If yes please let me know how.Does "libssh2_channel_exec" is able to provide all the data if command output is very big ?ThanksSubrataFrom: Peter Stuge <peter_at_stuge.se>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:> My intention is to run multiple commands sequentially over ssh and> get the output.It seems &quot;libssh2_channel_exec&quot; function> can only execute a single command over a session or channel. So> this option will not serve my purpose because commands may have> some sub-commands. So I need to retain the session or channel to> execute those sub-commands. Please let me know if my> understanding is wrong and kindly let me know how to execute> 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.> It seems only &quot;libssh2_channel_shell&quot; function can serve> my purpose because I can execute multiple commands on a established> channel / session. 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.> It also seems from the different ssh tutorials from net that> non-interactive session may serve my purpose because there is no> pty associated with the channel. So I have tried to comment out> the &quot;libssh2_channel_request_pty&quot; call , but unfortunately!> result is the same(server do not send all data). What could be> 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't fix that in the client. There can be other reasons, you'llhave to study the particular server software you want to support indetail.> Lastly is there anyway to get all output data of commands or> sub-commands without using terminal emulation ??Please clarify what you mean by "sub-commands" ?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
xx.se/cgi-bin/mailman/listinfo/libssh2-devel
_______________________________________________
libssh2-devel https://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2018-10-29