Ssh – Run the same script on several servers through SSH

scpscriptingssh

I regularly need to update some Ubuntu 12.04 (Precise Pangolin) servers (Rackspace).

What I do now is:

  • Copy a file to a server using SCP
  • Log on to the server using SSH
  • Stop Tomcat
  • Do some copying and moving of the uploaded file
  • Start Tomcat

Repeat the exact same process with the same file on the second server (12 servers now and the number is growing).

Is it possible to write a script that loops through a list of servers and does all this for me?

How would I go about it?
Preferably the solution would not necesitate the install of any stuff. The majority within the company works on MacBooks, but Windows VM's are abundant.

Ideally servers to be updated can simply be added/removed to change the list of servers. However, any solution that saves me the time of doing the same thing +12 times is very much appreciated 🙂

Best Answer

There are several solutions for this - do you want to keep manual control of the steps and simply run through them simultaneously? The look at CSSH (if you're coming from a Linux system) or SuperPutty (if you're coming from a Windows system). If you simply want to automate everything, look at Expect.

Related Question