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

Jeff Lightner jlightner at water.com
Thu Apr 9 13:17:03 EDT 2009


I guess that might be one way to go.

 

However, I just realized on reading it on the list that my last response
(and the test I did that generated it) had a typo.  I had added "/log"
after the variable but it is part of the variable so expansion was
making it .../log/log/... instead of just .../log/... 

 

On retesting without the typo it seems to work with the double quotes.  

 

Apparently in one of my earlier iterations (where I was doing something
much more convoluted) I'd tried the double quotes and they didn't work
so I hadn't tried them after I got more or less the right syntax
(without variables).

 

________________________________

From: ale-bounces at ale.org [mailto:ale-bounces at ale.org] On Behalf Of
Jerald Sheets
Sent: Thursday, April 09, 2009 1:03 PM
To: Atlanta Linux Enthusiasts - Yes! We run Linux!
Subject: Re: [ale] Using locally defined variable in ssh command line
toremote host?

 

Is using expect and funneling your commands through an Expect script an
option?  

--j

On Thu, Apr 9, 2009 at 12:56 PM, Jeff Lightner <jlightner at water.com>
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

As I said I've tried various quoting, escaping, eval methods.  The issue
is they all make it either pass the variable (not its value) to the
other side so it doesn't know the value or they evaluate parts of the
command locally where they have no relevance.

It just seems really odd to me that ssh doesn't have something built in
that would allow it to process a locally defined variable on the remote
side.  I see many have asked the question but didn't see any obvious
solution.


-----Original Message-----
From: ale-bounces at ale.org [mailto:ale-bounces at ale.org] On Behalf Of JK
Sent: Thursday, April 09, 2009 12:20 PM
To: Atlanta Linux Enthusiasts - Yes! We run Linux!
Subject: Re: [ale] Using locally defined variable in ssh command line to
remote host?

Jeff Lightner wrote:
> Question:
>
> How can I create a variable in a script such that defining it on
> originating host allows me to feed it its value into the ssh command
> line on remote host?
>
>
>
> Details:
>
> I'm trying to do something like this:
>
>
>
> #!bin/bash
>
> REMSERVER=billybob
>
> REMLOGDIR=/felix/preprod/jboss/server/default/log
>
>
>
> ssh $REMSERVER 'sh -c "ls -tr  ${REMLOGDIR}/webserver.log* |xargs grep

> -hA 10 DEBUG"'


Hmmm.  Problem is, your variable is inside a single-quoted string, so it
isn't getting expanded on the local host.  Is there a specific reason
you're not just saying

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

?


-- JK

--
A closed mouth gathers no feet.
_______________________________________________
Ale mailing list
Ale at ale.org
http://mail.ale.org/mailman/listinfo/ale

Please consider our environment before printing this e-mail or
attachments.
----------------------------------
CONFIDENTIALITY NOTICE: This e-mail may contain privileged or
confidential information and is for the sole use of the intended
recipient(s). If you are not the intended recipient, any disclosure,
copying, distribution, or use of the contents of this information is
prohibited and may be unlawful. If you have received this electronic
transmission in error, please reply immediately to the sender that you
have received the message in error, and delete it. Thank you.
----------------------------------

_______________________________________________
Ale mailing list
Ale at ale.org
http://mail.ale.org/mailman/listinfo/ale




-- 
---
Jerald M. Sheets jr.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.ale.org/pipermail/ale/attachments/20090409/ea6b457f/attachment-0001.html 


More information about the Ale mailing list