peter360 wrote:
> So, just to make sure I really understand this, here is how I understand ssh
> worked: even thought I gave the command bash -c 'ulimit -a' as 3 separate
> strings,


> ssh (either the client or the server) actually concatenate them into
> one,

No.  It isn't put into one string unless you quote it as one string.

> and sshd forks a shell to parse the concatenated command string,
> in this case "bash -c ulimit -a".    Correct me if I am wrong.

On the remote server a $SHELL (specified in /etc/passwd, not
necessarly the same shell as on the client machine, a long standing
issue with rsh/ssh) parses the arguments /again/.  Which means you
almost always need two layers of quoting if quoting is needed.  One
for the local shell.  One more for the remote shell.

> >   echo ulimit -a | ssh localhost bash

This style avoids the quoting problem entirely and guarentees that the
remote shell is bash regardless of different /etc/passwd
configuration.  However it does use stdin and it is no longer
available for the remote command, if that is important.  Useful when
it can be used however.

Also, my example had a problem.

> >   ssh localhost "bash -c 'ulimit -a'"

I should have added the -n option to ssh so that it wouldn't read from
stdin.  In the above if used in a script it will read and consume any
input that may have been expected for a different command.

  ssh -n localhost "bash -c 'ulimit -a'"


Reply via email to