[英]one line command to execute multiple ssh command
我有一个包含主机信息的文件,一个主机一行
host1
host2
host3
我想做的是
ssh host1 'my command'
ssh host2 'my command'
ssh host3 'my command'
我如何使用一行命令来实现它(不是复杂的shell脚本),谢谢
这对于您想要的而言是否太复杂了?
for h in $(<file); do ssh $h 'my command'; done
另一种可能性:
cat file | xargs -I% -- ssh % 'my command'
或更短:
<file xargs -I% -- ssh % 'my command'
或更短(如果您确定自己的ssh命令中没有-
选项):
<file xargs -I% ssh % 'my command'
while read -r line; do ssh "$line" 'my command'; done < host
该命令将逐行读取文件,并将每一行保存到变量$line
。 并使用保存在$line
的主机执行ssh命令
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.