Thanks all. Turns out Expect was the way to go for me ... actually pexpect
(a pure python implementation). There is a simple little ssh session example
that comes with the module (originally hacked together by none other than
ESR).

http://pexpect.sourceforge.net/pexpect.html

I'm thinking this might be our topic for tomorrow night's python meeting :-)

Thanks a million guys,
Greg


2009/4/8 Mark Carlson <[email protected]>

> On 4/8/09, Mark Carlson <[email protected]> wrote:
> > On 4/8/09, Greg Saunders <[email protected]> wrote:
> >  > Hi all, I'm looking for the best way to run a remote process. SSH with
> keys?
> >  > "ssh [email protected] remoteprocess"
> >  >
> >  > Is there a better way, especially if you have to execute 20 remote
> commands
> >  > each time and those commands are determined on the fly and not known
> ahead
> >  > of time.
> >  >
> >  > Thanks!
> >  > Greg
> >
> >
> > "best" really depends on your situation...
> >
> >  Personally, I find SSH to be the best for me.  If you need to use
> >  keys, use them, if you don't want to, don't.
> >
> >  If you want to execute 20 commands, use a list of commands.
> >
> >  Some simple examples:
> >  # Commands are executed sequentially:
> >  % command1; cmd2; cmd3
> >  # Commands are only executed if the previous one returns zero:
> >  % command1 && cmd2 && cmd3
> >  # Commands are only executed if the previous one returned nonzero
> (error):
> >  % command1 || cmd2 || cmd3
> >
> >  A more complex example:
> >  # Run command 1, then command 2, and finally command 3 only if command
> >  2 did not return an error
> >  % command1; cmd2 && cmd3
> >
> >
> >  From the bash man page: http://linux.die.net/man/1/bash
> >  ----------------------------------------
> >  Shell Grammar
> >  <...>
> >
> >  Lists
> >
> >  A list is a sequence of one or more pipelines separated by one of the
> >  operators ;, &, &&, or ||, and optionally terminated by one of ;, &,
> >  or <newline>.
> >
> >  Of these list operators, && and || have equal precedence, followed by
> >  ; and &, which have equal precedence.
> >
> >  A sequence of one or more newlines may appear in a list instead of a
> >  semicolon to delimit commands.
> >
> >  If a command is terminated by the control operator &, the shell
> >  executes the command in the background in a subshell. The shell does
> >  not wait for the command to finish, and the return status is 0.
> >  Commands separated by a ; are executed sequentially; the shell waits
> >  for each command to terminate in turn. The return status is the exit
> >  status of the last command executed.
> >
> >  The control operators && and || denote AND lists and OR lists,
> >  respectively. An AND list has the form
> >     command1 && command2
> >  command2 is executed if, and only if, command1 returns an exit status of
> zero.
> >
> >  An OR list has the form
> >     command1 || command2
> >  command2 is executed if and only if command1 returns a non-zero exit
> >  status. The return status of AND and OR lists is the exit status of
> >  the last command executed in the list.
> >
> >  -Mark C.
> >
>
> Oh, and if you don't use quotes to enclose the commands, you may be
> surprised by the results!
>
> Ex: both commands run on remote machine:
> % ssh 127.0.0.1 "echo hello; echo world"
>
> Ex: "echo hello" run remotely, "echo world" run locally
> % ssh 127.0.0.1 echo hello; echo world
>
> The results look the same in this case... but if your commands are
> backing up a computer or something, you will soon notice a difference!
>
> -Mark C.
>
> _______________________________________________
> clug-talk mailing list
> [email protected]
> http://clug.ca/mailman/listinfo/clug-talk_clug.ca
> Mailing List Guidelines (http://clug.ca/ml_guidelines.php)
> **Please remove these lines when replying
>
_______________________________________________
clug-talk mailing list
[email protected]
http://clug.ca/mailman/listinfo/clug-talk_clug.ca
Mailing List Guidelines (http://clug.ca/ml_guidelines.php)
**Please remove these lines when replying

Reply via email to