Skip to main content
2 of 3
Commonmark migration

You're hitting a quoting problem; the $5 is being interpreted at the wrong time. There are at least two solutions:

  1. Put a \ before the $; e.g.

    /usr/bin/ssh -i /path/to/key user@server "df -h | grep /dev/root | awk '{print \$5}'"

  2. Run the df remotely but the grep and awk locally. e.g.

    /usr/bin/ssh -i /path/to/key user@server df -h | grep /dev/root | awk '{print $5}'

FWIW, I'd run a version of the second option but merging grep and awk

/usr/bin/ssh -i /path/to/key user@server df -h | awk '/\/dev\/root/ {print $5}'
Stephen Harris
  • 49.3k
  • 7
  • 115
  • 138