简体   繁体   English

bash while循环只能读一行

[英]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. ssh从stdin读取,因此它将占用文件的其余部分。 Run ssh with the -n option to redirect its input to /dev/null. 使用-n选项运行ssh将其输入重定向到/ dev / null。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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