====== 09 SSH in While ======
This will display only one line.
while read NAME HOST CMD
do
ssh $NAME@$HOST "$CMD"
done
When you run SSH, stdin is directed at it, so the entire file is passed to SSH, not just the one line you read with read. Therefore, after executing SSH, there are no more lines to read, so the while loop will end in one go.
To prevent this, use the -n option to ssh to redirect /dev/null and not redirect stdin.
===== OK here =====
while read NAME HOST CMD
do
ssh -n $NAME@$HOST "$CMD"
done
{{tag>bash ssh while}}