Escape single quotes ssh remote command

I read any solutions for single quotes for a remote ssh command. But any work is fien.

I'm trying to

ssh root@server "ps uax|grep bac | grep -v grep | awk '{ print $2 }' > /tmp/back.tmp"

Awk doesn't work

ssh root@server "ps uax|grep bac | grep -v grep | awk \'{ print $2 }\' > /tmp/back.tmp"
....
awk: '{
awk: ^ caracter ''' inválido en la expresión

And try to put single quotas on the team, but also do not work.

Depressive help

+5
source share
2 answers

In the first attempt, you use double quotes ", so you need to escape the character $:

ssh root@server "ps uax|grep bac | grep -v grep | awk '{ print \$2 }' > /tmp/back.tmp"

Alternatively, you can use:

 ps uax | grep 'ba[c]' | ...

so you don’t need a step grep -v grep.

+7
source

ssh , , . , , . , , , .

, , . , bash .

ssh root@server ps uax \| grep ba[c] \| \'{ print \$2 }\' \> /tmp/back.tmp

, ( )

ssh root@server ps uax \| grep ba[c] \| "'{ print \$2 }'" \> /tmp/back.tmp

, , , , .

+8

All Articles