while loop to read file ends prematurely

后端 未结 4 1881
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-06 08:29

The eventual goal is to have my bash script execute a command on multiple servers. I almost have it set up. My SSH authentication is working, but this simple while loop is

4条回答
  •  盖世英雄少女心
    2021-01-06 08:48

    Assign to an array before the loop, so that you are not using stdin for your loop variables. The ssh inside the loop can then use stdin without interfering with your loop.

    readarray a <  hosts.list
    for HOST in "${a[@]}"; do 
           ssh $HOST "uname -a"
           #...other stuff in loop
    done
    

提交回复
热议问题