The issue is that $4
in the awk
program is part of a double quoted string. Since it is in double quotes, the (local) shell will expand it before calling ssh
.
In the shell, $4
is the 4th positional parameter, which most likely is empty. The means that the $4
in the awk
code will be replaced by an empty string, producing an invalid awk
program.
In this case, there is no need to run the awk
command on the remote host. Instead, just do
while IFS= read -r remote; do
ssh -n -o BatchMode=yes "$remote" 'df /var' | awk 'FNR == 2 && $5 > 80'
done </etc/gridhosts
Note that I've changed the awk
code to look at $5
on line 2 rather than at $4
on every line, as this is where the the percentage is usually located. Also, I've removed the -h
option for df
as it's not needed, and I've made the loop read the input file line by line rather than expanding the full contents of the file in a for
loop header (which is inelegant, and could, in the general case, eat a lot of memory unnecessarily).
You may also be interested in evaluating Ansible or similar software, as this would make doing cluster-wide operations much easier.
$4
is being passed to ssh inside double quotes with an unescaped dollar sign. Is that intentional?