[paramiko] How do I execute multiple commands in a single channel?

james bardin jbardin at bu.edu
Mon Mar 30 08:45:29 PDT 2009


On Mon, Mar 30, 2009 at 10:55 AM, James <rocketmonkeys at gmail.com> wrote:

> In the normal bash, you'd get a prompt when it's done.  I'm assuming
> when we run bash -s that's not the case.  Is there any other way to
> determine end-of-command?

If you're going the "expect" route, you can invoke an interactive
shell, set the prompt to something static, and look for that in the
output.

This is kind of how telnet lib does it. Actually, take a look at the
telnetlib source. It's simple, has some functions for doing
expect-like things, and may give you ideas on how to handle your
problem over ssh.


> Looks like I'll have to stick with
> exec_command() for now.  What I'm looking for is some hybrid... being
> able to do "export ENVIRO=something" in one set of commands, know when
> that command is done, and then execute more commands depending on
> that.  Looks like this combination of features isn't available  yet.
>

I'm still leaning towards pre-packaged shell scripts to deal with
these technical difficulties. The only other idea I've had, is to
write something like telnetlib for paramiko, but I feel the problem is
better solved in other ways.

This is how I've handled these things in the past (although, I usually
have nfs to distribute the files). Send some scripts over sftp with
paramiko, run what you need, and delete them when you're done. If you
don't like writing shell code, you could write the scripts in python,
and run them the same way.

In the same vein, you could send a "server" python script over, that
handles the commands locally, and gives you reliable feedback through
the ssh channel.


-jim



More information about the paramiko mailing list