[英]How to performe command in multiple servers through ssh?
I'm trying to execute command on multiple servers through ssh, that's what I'm trying to do: 我试图通过ssh在多台服务器上执行命令,这就是我要做的:
for i in {1..3}; do `ssh nginx_$i ps aux | grep logstash`; done
But it tells me to install some package: 但是它告诉我要安装一些软件包:
The program 'root' is currently not installed. You can install it by typing:
sudo apt-get install root-system-bin
I'm not convinced that I need to install it, because if I do 我不认为我需要安装它,因为如果这样做
ssh nginx_1 ps aux | grep logstash
It works, and gives me the correct result. 它有效,并且给了我正确的结果。
PS Assuming that I have configured .ssh/config
file to connect to nginx_1
, nginx_2
and nginx_3
. PS假设我已经配置了.ssh/config
文件以连接到nginx_1
, nginx_2
和nginx_3
。
for i in {1..3}; do `ssh nginx_$i ps aux | grep logstash`; done ^ ^
Drop the backquotes. 删除反引号。 If you include them, the shell will try to execute the output of the command. 如果包含它们,则外壳程序将尝试执行命令的输出。
而不是for循环,应该使用pssh 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.