Redirect loop
CAT $ app_file | the while the Read Line
do
SSH -q $ Line LS / Home / ADMIN
DONE
Fail: only executed once, and out of the loop
1. ssh command on each execution, reads the contents of all of the standard input.
cat file | ssh 1.1.1.1 cat will read the contents of all files
2. For a while loop, when used as follows:
cat file | while read line
As used herein, redirect the file to the contents of the input while command, while command reads the data from the input line per read.
The problem here, if you call the ssh command in a while loop, ssh will read all the data in the input current to go, which is the cat file to redirect data while command, ssh command are read left to as for when the next cycle, read read content is empty, leading to early termination of the cycle.
To solve this problem in two ways
1. ssh -n -n parameter using
2. ssh xxxx </ dev / null shell command input redirection
-l login user specified
-p Sets the port number
-f run in the background, and add the recommended parameters -n
-n redirects standard input to / dev / null, prevent the reading of standard input
-N Do not execute a remote command, the only port forwarding
-q quiet mode, ignore all error messages and conversations
-T Disable pseudo terminal configurationFirst, the redirection method; Pipeline Act: cat $ FILENAME | while read LINE
Function While_read_LINE(){
cat $FILENAME | while read LINE
do
echo $LINE
done
}
Note: I just put all this way is called pipeline method, we should be able to see out of it compared. When the input and output of the command will meet pipeline when pipeline to the left as to the right of the pipe command is then input it.
Second, examples
1, pri.sh
2, Dirr
CAT $ app_file | the while the Read Line
do
SSH -q $ Line LS / Home / ADMIN
DONE
Fail: only executed once, and out of the loop
1. ssh command on each execution, reads the contents of all of the standard input.
cat file | ssh 1.1.1.1 cat will read the contents of all files
2. For a while loop, when used as follows:
cat file | while read line
As used herein, redirect the file to the contents of the input while command, while command reads the data from the input line per read.
The problem here, if you call the ssh command in a while loop, ssh will read all the data in the input current to go, which is the cat file to redirect data while command, ssh command are read left to as for when the next cycle, read read content is empty, leading to early termination of the cycle.
To solve this problem in two ways
1. ssh -n -n parameter using
2. ssh xxxx </ dev / null shell command input redirection
-l login user specified
-p Sets the port number
-f run in the background, and add the recommended parameters -n
-n redirects standard input to / dev / null, prevent the reading of standard input
-N Do not execute a remote command, the only port forwarding
-q quiet mode, ignore all error messages and conversations
-T Disable pseudo terminal configurationFirst, the redirection method; Pipeline Act: cat $ FILENAME | while read LINE
Function While_read_LINE(){
cat $FILENAME | while read LINE
do
echo $LINE
done
}
Note: I just put all this way is called pipeline method, we should be able to see out of it compared. When the input and output of the command will meet pipeline when pipeline to the left as to the right of the pipe command is then input it.
Second, examples
1, pri.sh
2, Dirr