Skip to main content
1 of 3
Stephen Harris
  • 49.4k
  • 7
  • 115
  • 138

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}'"

  1. 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.4k
  • 7
  • 115
  • 138