ssh break the while loop.
0</dev/null
or -n
option of ssh
can resolve this problem.
#!/bin/bash
cmd="ps -ef | awk '{print \$2}'"
while read node ; do
pids=$(0</dev/null ssh "root@$node" "$cmd")
echo "$node" $pids
done
#!/bin/bash
cmd="ps -ef | awk '{print \$2}'"
while read node ; do
pids=$(ssh -n "root@$node" "$cmd")
echo "$node" $pids
done
# -n
is a more simple and direct way!