Skip to main content
Formatting
Source Link
AdminBee
  • 23.6k
  • 25
  • 55
  • 77

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

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

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

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

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}'
Commonmark migration
Source Link

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.

    Put a \ before the $; e.g.

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

/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.

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

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

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

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}'
Source Link
Stephen Harris
  • 49.3k
  • 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}'