I am trying to execute a single remote command via ssh for debugging setup. This does not execute the correct command (I cannot see the output but it seems the PID is missing to gdbserver):

ssh -t admin@myhost.com "ps -A | grep myprocess | awk '{print $1}' | xargs -I{} gdbserver --attach {}"

while doing it local works:

ps -A | grep myprocess | awk '{print $1}' | xargs -I{} sudo gdbserver --attach {}

Where does it go wrong in the parsing?

  • 2
    You're missing the awk '{print $1}' from the first command.
    – Ladadadada
    Dec 22, 2020 at 12:34
  • oh typo in question, fixed
    – Rolle
    Dec 22, 2020 at 12:38

1 Answer 1


I tried this out myself and debugged by inserting an echo command:

ssh -t admin@myhost.com "ps -A | grep rsyslogd | awk '{print $1}' | xargs -I{} echo gdbserver --attach {}"

The last part that should have been just the PID was instead:

1209 ?        00:00:05 rsyslogd

My guess is that the $ sign in the awk was being interpreted by bash somewhere and turned into an empty string, so the awk command was just {print}.

Adding a backslash before the $ fixed it and produced a final command that includes just the PID.

ssh -t admin@myhost.com "ps -A | grep rsyslogd | awk '{print \$1}' | xargs -I{} echo gdbserver --attach {}"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.