I am having an issue passing a command through ssh which uses an environment variable. I would like the environment variable to be read from the remote host, but it is being read from the local host. For instance: ssh rhost ls -lm $WWW_HOME $WWW_HOME is set as /usr/www on local but /var/www on the remote so it is being read as : ssh rhost ls -lm /usr/www and I'd like it to be ssh rhost ls -lm /var/www Any thoughts would be appreciated, thanks for your help.
On Tue, Oct 10, 2006 at 11:09:43AM -0700, Clark Menard wrote:> I am having an issue passing a command through ssh which uses an environment variable. I would like the environment variable to be read from the remote host, but it is being read from the local host. > > For instance: > > ssh rhost ls -lm $WWW_HOME >ssh rhost ls -lm \$WWW_HOME The issue is that your command is being variable interpolated by your local shell before executing ssh. You want to pass a literal '$WWW_HOME' argument to ssh (so it can pass it over the ssh channel), so you need to escape it from the local shell. - Bill
On Tue, 10 Oct 2006, Clark Menard wrote:> I am having an issue passing a command through ssh which uses an > environment variable. I would like the environment variable to be read > from the remote host, but it is being read from the local host. > > For instance: > > ssh rhost ls -lm $WWW_HOMEtry: ssh rhost "ls -lm $WWW_HOME" otherwise your local shell will digest the environment variable in your command line without passing it to the other end.
please send it to the list :) On Tue, 10 Oct 2006, Tim Rice wrote:> [ not sent to list] > On Wed, 11 Oct 2006, Damien Miller wrote: > > > try: > > > > ssh rhost "ls -lm $WWW_HOME" > > Actually that would be. > ssh rhost 'ls -lm $WWW_HOME' > > -- > Tim Rice Multitalents (707) 887-1469 > tim at multitalents.net > > >
Thank you for the follow up, this works perfectly. Clark ----- Original Message ---- From: William Ahern <william at 25thandClement.com> To: Clark Menard <menard_1 at yahoo.com> Cc: openssh-unix-dev at mindrot.org Sent: Tuesday, October 10, 2006 5:57:35 PM Subject: Re: Use remote machine environmental variables On Tue, Oct 10, 2006 at 11:09:43AM -0700, Clark Menard wrote:> I am having an issue passing a command through ssh which uses an environment variable. I would like the environment variable to be read from the remote host, but it is being read from the local host. > > For instance: > > ssh rhost ls -lm $WWW_HOME >ssh rhost ls -lm \$WWW_HOME The issue is that your command is being variable interpolated by your local shell before executing ssh. You want to pass a literal '$WWW_HOME' argument to ssh (so it can pass it over the ssh channel), so you need to escape it from the local shell. - Bill