bash 脚本中的 ssh 退出循环

ssh in bash script exits loop

我正在尝试 运行 在几个远程主机上执行一些命令。我在文件 ips.txt 中有他们的 ips 列表(每行一个 ip)。

#!/bin/bash

while IFS= read -r wip; do
    echo $wip
    ssh root@$wip "pkill pgm; cd /root/pgm; nohup ./pgm  > /dev/null 2>&1 &"
    echo "$wip end"
done < ips.txt

我正在 运行上面的脚本。但问题是在读取第一个 ip 后循环退出。但是如果我删除 ssh 行,它会打印所有 ips。

ssh 从标准输入 (ips.txt) 读取所有内容。

替换

ssh

ssh -n

参见:man ssh