0

I have x servers that I can connect via SSH via passwords. If I have to connect with only 1, I will ssh root@IPaddress. It will then ask for my password, and when authenticated, I can execute commands there.

What if I have x servers all being the same and I wish to execute the same command on every one of them? How can I do this with a single command or two?

3 Answers3

2

It sounds like you want a provisioning tool such as ansible, saltstack, chef or puppet.

Ansible works in a very similar way to what you want, you run it locally and it sshs into remote servers to run commands (there is no need to install an agent on the remote servers like the other products listed above). For example given a list of servers in /etc/ansible/hosts you can run ansible all -a "/bin/echo hello" to execute the given command on all servers. Full guide here.

But in addition to this you can start to craft playbooks of useful commands that let you rerun them on hosts in the future and work towards automating management of your infrastructure.

Alternatively you can use commands like pssh for running batch commands in parallel or using the synchronize-panes feature of tmux to run commands interactively across multiple hosts.

1
  1. Running same command(s) on several hosts

What if I have x servers all being the same and I wish to execute the same >command on every one of them? How can I do this with a single command or two?

You can run a script which get as a parameter the host name, and execute the same commands on the host-name in the parameter

  1. Connecting via SSH to multiple servers

It is highly recommended that you will using ssh key-pair, and the ssh communication will be password-less

see this answer

Yaron
  • 4,289
0

You can use MobaXtrem as ssh client , it has MultiExec feature witch allow you to execute the same commands to all opened terminal.

hnajib
  • 36