shell script while only executed once

The example code

while read line ;
do
ssh  -p20002 $line  -o StrictHostKeyChecking=no xxxxxxxxx
done < ip.txt

while only one cycle of reasons:

while reading the first line of text, and then execute the cycle, this time to execute ssh, ssh reads as standard input (stdin), all texts are read, so while there is no data, then out of the loop.

Solution:

Ssh -n parameter in use;


-n Redirects stdin from /dev/null (actually, prevents reading from stdin).This must be used when ssh is run in the background.

About to be redirected to the standard input/dev/null

Guess you like

Origin www.cnblogs.com/boxker/p/11232051.html