Daniel Stenberg wrote:
> On Fri, 4 Sep 2009, Dmitry V. Krivenok wrote:
>
>> My program executes many remote commands like
>>
>> ssh 192.168.70.205 cat /proc/meminfo | grep MemTotal | awk '{print $2}'
>> ssh 192.168.70.205 cat /proc/cpuinfo | grep processor | wc -l
>> ssh 192.168.70.205 uptime
>
> ssh 192.168.70.205 "cat /proc/meminfo | grep MemTotal | awk '{print
> $2}'; cat /proc/cpuinfo | grep processor | wc -l; uptime"
>
> There. Three commands in one connection. No magic.
It isn't the same.
In your example commands aren't run simultaneously.
Suppose I want to start 500 commands in parallel (I know about fork
bombs :)). I can't just concatenate them into the single line passed to
"sh -c" due to argument length limitation.
>
>> The question is can I use _current_ version of libssh2? Does it
>> support: 1) Creation of N "session" channels inside of SSH session and
>> calling "exec" in each channel? These channels should be active
>> simultaneously, i.e. all remote commands should run simultaneously.
>
> Yes it does. Or at least should.
>
>> 2) I consider every channel as a source of events ("new data
>> available", "command exited", "command was killed by signal", "error
>> occurred"). I want to implement event loop, so I need some kind of I/O
>> multiplexing function, which waits for requested events. To limit
>> maximum execution time of remote commands I should pass timeout to
>> this function.
>
> Is this a question?
>
> libssh2 does not feature any fancy channel switch that can direct or map
> actions on channels to specific events somehow. I bet that could be
> useful in a scenario such as the one you describe.
>
>> 3) If I found that remote command "hung", I should kill it via sending
>> the
>> signal (SSH_MSG_CHANNEL_REQUEST with type "signal").
>
> I don't think it supports that.
I think that it's very bad.
I wrote simple program which connects to openssh server, creates two
channels, executes long running program in each channel and exits
(without waiting for commands completion).
sshd's child process finds that read() returns 0 (FIN segment received)
and closes its socket.
Then sshd's child process terminates.
However, it doesn't terminate previously executed program (its child).
Process with PID=1 (init) becomes new parent of the process.
And finally we lost control over our program :(
I'm not sure about what's wrong here.
Maybe sshd is not properly configured, maybe it's not responsible for
termination of spawn process (what does RFC say about this?).
Anyway we must have a way to terminate remote process and SSHv2 protocol
supports it via sending the signal.
>
>> 4) I need to read STDOUT/STDERR of remote command and get exit status.
>
> I think you can get those.
>
>> I'm not sure that everything I need is already implemented in libssh2.
>> If not, is it possible to implement it using facilities provided by
>> libssh2?
>
> Everything within the SECSH protocol is possible to implement I'm sure.
>
Thank you very much for your response!
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2009-09-07