Run the same command on multiple Linux servers

October 22, 2015 — Leave a comment

Without getting too fancy, here’s a way that you can run a command on multiple servers at once. We’ll use an example of blocking a bad IP in CSF on each machine..

Let’s say you have 5 Linux servers:

We’ll also say that we have already set up SSH keys for each of them from our ‘key’ server, which we’ll use to run the script.

Now, let’s say that we noticed someone trying to brute force their way in on another server.. their ip address is:

Copy the script below into something like /usr/local/bin/

You will get something like this:

You can also do other commands of course.. like check the time/date on each one:
Change the 2nd to last line to:

And you get something like:

Have fun with it!

No Comments

Be the first to start the conversation.

Leave a Reply