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.

_______________________________________________
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