Executing a command on multiple droplets

May 5, 2019 206 views
API Automated Setups Ubuntu


I was wondering if there is a way that I could refresh my GitHub repository and restart my server by executing a command on multiple droplets at once. All I need the ability to do is execute a command on multiple of my droplets’ linux terminal on ubuntu.


1 Answer


Yes you can easily do that with a for loop.

  1. Create a file with a list of all of your servers, for example call it servers.txt and add your IPs on different lines.
  2. Example:

  3. Then with the following loop you can loop though all those servers and execute your commands

    for server in $(cat ./servers.txt) ; do 
    ssh root@${server} 'COMMAND1; COMMAND2; COMMAND3'

Hope that this helps!

Have another answer? Share your knowledge.