Running scripts on multiple servers at once

Philippe Lafrance
1 min readMar 10, 2016

I recently faced an issue where I needed to backup dozens of mysql servers which were not accessible via external mysql connections.

One solution would’ve been to loop through ips, create an ssh tunnel and then call mysqldump locally. The other option was to create a script that would connect to all servers and run commands via ssh.

I chose the latter solution and after some googling, came up with this:

  • collect all ips in a file called /home/list_of_servers
  • copy the ssh key on the target ip
  • connect to the ip via SSH and create a mysqldump
  • finally, use scp to download the remote sql file on local machine

Any other problem that can be solved by running identical commands on all servers can be solved by this script.

Chef, Ansible and Puppet were not an option at the time, but you might want to look at those if you need to manage many servers at once.

--

--