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:
192.168.0.5
192.168.0.6
192.168.0.7
192.168.0.8
192.168.0.9

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: 123.123.123.123.

Copy the script below into something like /usr/local/bin/block_bad_guy.sh

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