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互信
执行那个后发现每次只能关闭一台机器脚本就退出了。需要再次执行才能关闭后面的机器,请问是为什么?谢谢
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.
ssh -n
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 $
while reading HOSTNAME do ssh root@$HOSTNAME "poweroff" done < host.log
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 $
HOSTNAMEwhile reading HOSTNAME
do
ssh root@$HOSTNAME "poweroff"
done < host.log