quote escaping over ssh
Sean Keating
sean at csupport.com
Wed Mar 19 20:01:01 PDT 2014
Wouldn't the correct way to escape the quotes be:
ssh root at myhost.com 'grep \'\"priority\":\"err\"\' /var/log/local7.log'
The way you have it you are only escaping the second \.
Also, someone suggested that you place the command on the remote
machine, but you said it would be to difficult to maintain. Have thought
about writing a script on your machine that copies the current script to
your list of a thousand servers, runs the script, and then deletes the
remote script?
Just a thought.
Sean
On Wed, 2014-03-19 at 15:26 -0700, Lonni J Friedman wrote:
> Hi folks,
> I've got a bizarro problem that is driving me mad. I need to run a
> command that has both single & double quotes, over ssh. This is the
> command which runs just fine if I'm already using an interactive shell
> on a system:
> grep '"priority":"err"' /var/log/local7.log
>
> Yes, I'm dealing with some crazy json formatted logs, which I have no
> control over.
>
> However, what I want to do is run that command from a non-interactive
> session over ssh. I've tried different ways of escaping the quotes,
> and nothing works. This command isn't escaped properly and the entire
> ssh command fails to run:
> ssh root at myhost.com 'grep \'"priority":"err"\' /var/log/local7.log
>
> This seems to work, but the ssh command just hangs forever (normally
> takes 1-3s to return):
> ssh root at myhost.com 'grep \\'"priority":"err"\\' /var/log/local7.log'
>
> Surely I'm missing something simple?
>
> thanks
>
>
--
Sean Keating
Computer Support, Inc
Office: 401-885-2297
Cell: 401-225-3545
<sean at csupport.com>
More information about the Linux-users
mailing list