A simple question, say I want to ssh to cluster machines and monitor some info of each of them. Specifically, I want to run nvidia-smi
on each of them to know the GPU usage of them. I tried:
for host in machine1 machine2 machine3
do
ssh "$host"
nvidia-smi
done
but it only logs in to machine1
, then just stopped there. Only after I exit machine1
, will nvidia-smi
execute, but on the local terminal, not on machine1
. Then it logs in to machine2
and stops there...
Put the command you want to execute on the
ssh
line:You might need to specify the full path of
nvidia-smi
.Also, rather than hard-coding your list of servers into this script (and other, similar scripts), keep the list in a file:
And change the
for
line to:Then, when the "list of servers" changes, you only have to change ONE place, not every script.