bash while循环只能读一行 [英] bash while loop read only one line

查看:64
本文介绍了bash while循环只能读一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对此代码有疑问.

  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 从stdin读取,因此它将占用文件的其余部分.使用 -n 选项运行 ssh ,将其输入重定向到/dev/null.

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.

这篇关于bash while循环只能读一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆