ssh in bash script exits loop [duplicate]

。_饼干妹妹 提交于 2021-01-28 01:44:56

问题


I am trying to run some commands on few remote hosts. I have the list of their ips in a file ips.txt (one ip per line).

#!/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

I am running the above script. But the problem is after reading the first ip the loop exits. But if i remove the ssh line, it prints all ips.


回答1:


ssh reads everything from stdin (ips.txt).

Replace

ssh

with

ssh -n

See: man ssh



来源:https://stackoverflow.com/questions/47858222/ssh-in-bash-script-exits-loop

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!