[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: using ssh_channel_write for command execution problem


Hi Andreas,

it's really strange. I made a simple C++ wrapper around the libssh API -
the exact code from my first post. When I do this:

SshSession session;
session.getShell("localhost", 22, "user", "pass");
boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
session.write("echo 123\n");
boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
session.close();

it always works. When I leave the this_thread::sleep out it never works. Is
there a way to clear any buffers or push everything to the server and get
some sort of ACK from it? I tried with ssh read before or after and it
works, probably it has the same effect as this_thread::sleep (delaying
something somewhere).

št 7. 11. 2019 o 16:28 Andreas Schneider <asn@xxxxxxxxxxxxxx> napísal(a):

> On Thursday, 7 November 2019 16:24:01 CET Karah Sekir wrote:
> > yes I have seen exec.c, I believe that ssh_channel_exec() without shell
> > executes exactly 1 command, but what I am trying to achieve is executing
> > multiple related commands that put the shell into a certain mode and then
> > read some data. That's why I request the PTY, then shell and then I would
> > use multiple ssh_channel_writes.
> >
> > I think this is not a libssh bug or anything, seems like an environment
> > issue - libssh sends data correctly, probably the system/server says
> > everything was sent correctly but the data is never executed on the
> server.
> > It's mind-boggling, no idea what could be the cause.
>
> a) you need a non-interactive shell
>
> http://api.libssh.org/stable/libssh_tutor_shell.html
>
> b) you should to check if it succeeded or not
>
> ./mycommand && echo OK || echo KO
>
> So after you sent it, read from the channel and create a command protocol.
>
>
> Let me know if you get it working. It would be great to get
>
> http://api.libssh.org/stable/libssh_tutor_shell.html
>
> updated with an example for this.
>
>
>         Andreas
>
> --
> Andreas Schneider                 asn@xxxxxxxxxxxxxx
> GPG-ID:     8DFF53E18F2ABC8D8F3C92237EE0FC4DCC014E3D
>
>
>

References:
using ssh_channel_write for command execution problemKarah Sekir <jackiechanaaa@xxxxxxxxx>
Re: using ssh_channel_write for command execution problemAndreas Schneider <asn@xxxxxxxxxxxxxx>
Re: using ssh_channel_write for command execution problemKarah Sekir <jackiechanaaa@xxxxxxxxx>
Re: using ssh_channel_write for command execution problemAndreas Schneider <asn@xxxxxxxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org