If you want to use SSH bulk login to the operation of other systems, we will use a circular way to deal with, then there is a huge pit, you have to be careful.
Now you want to use a script to get the remote server side/root the following file:
1 # !/bin/bash 2 3 ' IP . txt '| while Read Line;do 4 echo $line5 access= ' ssh ' 6 Done
The Result: The script only detects the first IP and jumps directly to the loop .
Problem Analysis:
While using the redirect mechanism, the information in the Ip.txt file has been read into and redirected to the entire while statement, so when we call the Read statement again in the while loop, the next record is read. The problem here is that the SSH statement just reads everything in the input. To prevent SSH from reading all things add a </dev/null, redirect the input of SSH into the input.
resolution Policy:
1. Use a For loop to represent while, because for not one time the file content cache is fetched, the code snippet is modified as follows:
1 for inch ' cat ip.txt '; 2 Echo $ip3 access= ' ssh $ip " '4 Echo $access5 done
2, if you persist in using the while loop, you need to add the-n parameter to SSH, why the addition of the-n parameter can also solve the problem? Read the description of the-n parameter through man SSH
Redirects stdin from/dev/null (actually, prevents reading from stdin)
1 # !/bin/bash 2 3 ' Ip.txt '| while Read Line;do 4 echo $line5 " "6 Done
Linux uses SSH to the remote and uses the while pit