I am trying to run an inline ssh command which looks like this:
ssh user@127.0.0.1 "df / -h | awk 'FNR == 2 {print $3}'"
I would expect the output to be 3.8G
(as this is the second line, third column) but instead, I am getting /dev/sda1 6.9G 3.8G 2.8G 58% /
(the entire second line).
This means that the FNR == 2
is working but the {print $3}
is not.
If I run that command directly on the machine that I am ssh'ing into then I get the expected result, just not when calling it through an inline ssh command as above.
This code will eventually ran within a bash script. Is it not possible to use print in this way? If not, is there another method that you can suggest? I am relatively new to terminal life so please bear with me.