Remote ssh command with arguments

I know that I can remotely run a command from another computer using the ssh -t login @machine command, however I am trying my best to execute a more complex command:

 watch  "ps aux  | awk '{print $1}' | grep php-fpm | wc -l"

I am trying to use different quotes, although the clock command seems to work and it shows errors like:

awk: cmd. line: 1: {print awk: cmd. line: 1:
^ unexpected news or end of
line

+4
source share
1 answer

A thing is $expanded by the shell before being passed to the team ssh. You should deprive him of his special importance locally, avoiding it before passing it on sshas a

ssh -t login@machine watch "ps aux | awk '{print \$1}' | grep php-fpm | wc -l"

, , , , $1, , , awk.

, awk grep

ssh -t login@machine watch "ps aux | awk '\$1 == \"php-fpm\"{count++}END{print count}'
+4

Source: https://habr.com/ru/post/1691968/


All Articles