Subject: Multiple commands execution.

Multiple commands execution.

From: Dmitry V. Krivenok <krivenok_at_orangesystem.ru>
Date: Fri, 04 Sep 2009 17:43:46 +0400

Hello!

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

to get information about remote host.

It works fine if the number of hosts and amount of information for each host
is relatively small.
However, if the number of hosts is greater than (for example) 1000 it
becomes
the problem, since I have to fork one process (ssh utility which comes
with openssh
package) per parameter.

Unfortunately, I can't write script which returns information about
_all_ required
parameters and copy it to all remote hosts.

Obviously, every ssh program does at least this:
* Establishes new TCP connection
* Performs things described in SSH-TRANS
* Performs things described in SSH-USERAUTH
* Performs things described in SSH-CONNECT, including creating new channel,
initiating command execution, reading command's STDOUT/STDERR, etc.

For a task of obtaining N parameters from remote host this sequence
seems really
redundant.
The idea is to write a program which executes N remote commands using only
one SSH connection. Such program allows significantly reduce the number of
forks, number of TCP connections, etc.

I'm new to SSH protocol and libssh2 library.
Today I read some sections of SSH-ARCH and SSH-CONNECT and I think that
it's possible to implement my idea.
Am I right?

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.
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.
3) If I found that remote command "hung", I should kill it via sending the
signal (SSH_MSG_CHANNEL_REQUEST with type "signal").
4) I need to read STDOUT/STDERR of remote command and get exit status.

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?

For example I didn't find anything about "signal" and "exit-signal" in
source code (but
I found "exit-status").

Thank you beforehand!

-- 
Sincerely yours, Dmitry V. Krivenok
Orange System Co., Ltd.
Saint-Petersburg, Russia
work phone: +7 812 332-32-40
cellular phone: +7 921 576-70-91
e-mail: krivenok_at_orangesystem.ru
web: http://www.orangesystem.ru
skype: krivenok_dmitry
jabber: krivenok_dmitry_at_jabber.ru
icq: 242-526-443
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2009-09-04