centos - shellscript 循环执行代码,但是每次执行一次以后就退出了?
过去多啦不再A梦
过去多啦不再A梦 2017-04-25 09:01:06
0
4
869
while read $HOSTNAME
do
    ssh root@$HOSTNAME "poweroff"
done < host.log

host.log 中的内容:
192.168.122.1
192.168.122.2
192.168.122.3

机器配置过ssh互信

执行那个后发现每次只能关闭一台机器脚本就退出了。需要再次执行才能关闭后面的机器,请问是为什么?谢谢

过去多啦不再A梦
过去多啦不再A梦

reply all(4)
淡淡烟草味

Try writing this line like this: ssh root@$HOSTNAME "poweroff" < /dev/null

漂亮男人

or write ssh -n. The reason this happens is that ssh reads the rest of your stdin.

So I try not to use while + redirection to read data. If I want to read, I also use another file descriptor to read. stdin can easily be read by other commands.

黄舟

perl -ne 'system q/ssh/, q/root@/.$_,q/poweroff/' host.log #This should be fine

刘奇

Remove the $ in while read $

HOSTNAME

while reading HOSTNAME
do
ssh root@$HOSTNAME "poweroff"
done < host.log

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template