当while read line 遇到 ssh(转)
时间:2021-09-02 04:51:22
收藏:0
阅读:8
https://www.cnblogs.com/Peter2014/p/8342495.html
问题:while read line 中使用ssh只能读取一行?
|
1
2
3
4
5
6
|
#!/bin/shwhile read linedoecho $linessh root@$line "echo 123456 | passwd --stdin peter" > /dev/nulldone < hosts.txt |
结果hosts.txt中只有第一行ip地址生效,问题在于ssh默认也会从标准输入中读取数据,导致循环失败。
解决:使用for line in `cat hosts.txt`
|
1
2
3
4
5
6
|
#!/bin/shfor line in `cat hosts.txt`doecho $linessh root@$line "echo 123456 | passwd --stdin peter" > /dev/nulldone |
此外,还可以使用ssh -n 来避免ssh读取标准输入。
原文:https://www.cnblogs.com/zhidian2020/p/15213480.html
评论(0)