MultiServ : Execute terminal commands on several servers at once

Hi guys,

I just wanted to share with you a script I made, just in case it could help some of you.

It allow you to open several Terminal tabs that, each one of them launch a SSH connexion with one server. Then you can run a command on all the servers at once (usefull tu delete files, update servers…)

-- App : MultiServ
-- Purpose : Allow user to connect himself to several servers at once and run the same actions on all the servers (updates.)
-- Author : Gabriel BORDEAUX
-- Company : Galaxya
-- Website : http://www.galaxya.fr
-- Version : 1.0
-- Date : August 6th 2012
-- Licence : WTFPL - http://en.wikipedia.org/wiki/WTFPL

-- Configure/install : It's easy. Just edit server list (just bellow), then edit ssh login script on the line "if Serveur = "Server 1" then" and bellow, then, have fun. Comments are welcome, just let me know if you have any questions. Hope this little script helps. Gabriel

-- Choix serveurs
set choices to choose from list {"Server 1", "Server 2", "Server 3", "Server 4"} with title "Choose one or more servers" with prompt "Choose one or more servers" OK button name "Go" cancel button name "Cancel" default items {"Server 1"} with multiple selections allowed

-- On recupere la liste des serveurs
set ListeServeurs to result

-- Affichage du term en premier plan
activate application "Terminal"

tell application "Terminal"
	activate
	-- On ouvre les onglts
	repeat with Serveur from 1 to count choices
		
		if Serveur is 1 then
			do script "echo $?" -- opens a new window
		else
			tell application "System Events"
				keystroke "t" using command down -- open tabs
			end tell
		end if
	end repeat
	
	delay 2
	
	-- On active les serveurs
	set NumWindow to 1 -- Numero de l'onglet
	repeat with counter_variable_name from 1 to count of ListeServeurs
		set Serveur to item counter_variable_name of ListeServeurs
		
		if Serveur = "Server 1" then
			set ActiveServer to "ssh gabriel@myserver1.net"
		else if Serveur = "Server 2" then
			set ActiveServer to "ssh gabriel@myserver2.net"
		else if Serveur = "Server 3" then
			set ActiveServer to "ssh gabriel@myserver3.net"
		else if Serveur = "Server 4" then
			set ActiveServer to "ssh gabriel@myserver4.net"
		end if
		
		-- on ouvre la connexion
		do script ActiveServer in tab NumWindow of window 1
		
		-- On incremente le numero de l'onglet
		set NumWindow to NumWindow + 1
	end repeat
end tell

-- Pause le temps de se connecter aux serveus		
delay 5

repeat
	-- On demande au client s'il veut executer une autre commande
	display dialog "What command should I send to the server ?" default answer "ls" buttons {"Send", "Cancel"} default button "Send" cancel button "Cancel"
	
	-- On recupere la commande
	set CommandeToDo to (text returned of result)
	
	-- Si aucune commande n'est saisie, on arrete le process
	if CommandeToDo = "" then exit repeat
	
	-- Execution des commandes
	tell application "Terminal"
		repeat with Serveur from 1 to count choices
			do script CommandeToDo in tab Serveur of window 1
		end repeat
	end tell
end repeat