简体   繁体   中英

bash while loop read only one line

I have issue with this code.

  while IFS='' read -r line
  do

    echo "host: "$line

    IP_addr=$(echo $line |cut -d" " -f1)
    host=$(echo $line | cut -d" " -f2)

    FILE_CHECK=$(ssh -o ConnectTimeout=10 $USER@$IP_addr "find $SRC_FILE -mtime 0")

    echo $FILE_CHECK

    ((host_num+=1))


    echo "" #empty line
  done < "$SERVER_LIST"

  echo $host_num

Where variable server list contain path to file with server

192.168.1.1 app1
192.168.1.2 app2
192.168.1.3 app3 

Script read first line, successfully connect to host and then exit. When I tried loop through file and only echo lines loop read all lines.

ssh reads from stdin, so it will eat the rest of the file. Run ssh with the -n option to redirect its input to /dev/null.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM