Report this

What is the reason for this report?

Executing a command on multiple droplets

Posted on May 5, 2019

Hello,

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.

Thanks



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi,

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.
  • Example: 192.168.0.2 192.168.0.3 192.168.04
  1. 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'
done

Hope that this helps!

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.