I tried mimic the solution provided in this answer, which finds and kills a process, and developed the following script which ssh to a list of machines specified in the input arguments and kill the desired process.
for node in "$@"; do
ssh $node "kill $(ps aux | grep '[s]omeprocess' | awk '{print $2}')"
done
The variable $2
used in the awk '{print $2}'
should be the second parameter passed by the grep [s]omeprocess
. However, it seems that the second input argument of the whole script is used instead (Am I wrong on this part). Can I know how my awk '{print $2}'
can really get the second parameter passed by the previous grep
operation? Or, is there a nicer way to find and kill a process across multiple machines? Thank you!