I’m trying to do a loop in a make to exec a remote ssh command to optain the pid of a process to kill it.
Like this:
target:
for node in 23 ; do \
echo $$node ; \
ssh user@pc$$node "~/jdk1.6.0_31/bin/jps | grep CassandraDaemon | awk '{print \$$1}'" > $(PID); \
ssh user@pc$$node "kill -9 $(PID); \
done
But I get:
/bin/sh: 3: Syntax error: ";" unexpected
The issue I think is to store the pid that the remote ssh command returns (it woks well without the > $(PID) )
>redirects into files, not into variables.$()captures in a way you can assign to variables… but is alsomakesyntax, so you need to escape it. You also need to escape it when you use it so that you don’t get themakevariable instead (no, you can’t store it in amakevariable).(assuming one of your many, many edits hasn’t changed things too much from when I copied and pasted that to fix it…)