[ale] Using locally defined variable in ssh command line to remote host?

JK jknapka at kneuro.net
Thu Apr 9 13:46:33 EDT 2009


Jeff Lightner wrote:
> Yes.  Because when I use the double quotes it tries to list the files on
> the local host rather than the remote one so results in:
> 
> ls: /felix/preprod/jboss/server/default/log/log/webserver.log*: No such
> file or directory


Good point. You need to be sure each shell expansion happens on the right
host.  So in this case, escape the glob character:

  ssh $REMSERVER "ls -tr  ${REMLOGDIR}/webserver.log\* |xargs grep -hA 10 DEBUG"

Then the variable expansions will both be done locally, and the glob
expansion will be done on the remote system, since one level of escapage
will be removed by the local shell and a literal "*" will be sent in the
command.

(Though to paraphrase Don Knuth: Beware of bugs in the above command. I
have only convinced myself it is correct, not actually run it.)

-- JK

-- 
A closed mouth gathers no feet.


More information about the Ale mailing list