bash脚本中的ssh退出循环 [英] ssh in bash script exits loop

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

问题描述

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

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

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

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.

推荐答案

ssh 从stdin(ip​​s.txt)中读取所有内容.

ssh reads everything from stdin (ips.txt).

替换

ssh

使用

ssh -n


请参阅: man ssh

这篇关于bash脚本中的ssh退出循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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