4

I'm having trouble issuing the following command on remote server. The | awk '{print $1}' did not appear to have any effect on the output. Am I incorrectly escaping the quotation characters? To make it worse, these two commands are actually submitted via a python script... thus making escape just more confusing...

On local server:

ssh remote.server.com "find /root/directory -type f -exec md5sum {} + | awk '{print $1}'"

On remote server:

find /root/directory -type f -exec md5sum {} + | awk '{print $1}' 
user3388884
  • 4,748
  • 9
  • 25
  • 34

2 Answers2

8

Let's ask shellcheck:

In yourscript line 1:
ssh remote.server.com "[...] | awk '{print $1}'"
                                           ^-- SC2029: Note that, unescaped, this
                                                       expands on the client side

There you go. You can escape it with a backslash.

that other guy
  • 116,971
  • 11
  • 170
  • 194
4

You can either escape $1 as \$1 Or run awk locally:

ssh remote.server.com "find /root/directory -type f -exec md5sum {} +" | awk '{print $1}'

Result should be the same.