bash - Loop only iterates once with `ssh` in the body -
this question has answer here:
i see questions same as...
while loop iterates once when call ssh in body of loop. while read -r line; ssh somehost "command $line" done < argument_list.txt
ssh reads standard input, first call ssh consumes rest of argument_list.txt before next call read. fix, either redirect ssh's standard input /dev/null using either
ssh somehost "command $line" < /dev/stdin or
ssh -n somehost "command $line" in event ssh does need read standard input, don't want reading more data argument_list.txt. in case, need use different file descriptor while loop.
while read -r line <&3; ssh somehost "command $line" done 3< argument_list.txt bash , other shells allow read take -u option specify file descriptor, might find more readable.
while read -r -u 3 line; ssh somehost "command $line" done 3< argument_list.txt
Comments
Post a Comment