Wednesday, November 18, 2009

dsh - distributed shell on Mac OSX

We have several hundred computers at work. One of the tools we use to interact with these machines is dsh, also known as dancer's shell or distributed shell. You can use dsh to run a command on a group of machines. For example, you could run the following command to find out what operating systems are running on a group of machines:
dsh "uname -a"
I'm going to give a short tutorial on how to set this up on the Mac for a group of machines with ssh available. First of all, I'm using MacPorts, so you'll need to have that installed before proceeding. With MacPorts installed, you can run the following command:
sudo port install dsh
After ports has done it's thing, you will need to create the proper directories:
mkdir -p ~/.dsh/group
The '-p' tells mkdir to create both .dsh and group directories. Neither of these directories existed for me. Now we need to create a 'group' file with the names of the machines we want to access:
vim ~/.dsh/group/testMachines
Add machine names to the file with one machine per line. For example:
pluto
mars
saturn
earth
You can create as many files in the ~/.dsh/group directory with this format. We will use these files to organize what machines we're sending commands to.

Now we need to create a config file:
vim ~/.dsh/dsh.conf
with the following contents:
verbose=0
remoteshell=ssh

waitshell=1 # whether to wait for execution
# 1 = run commands serially
# 0 = run commands in parallel

remoteshellopt=-lmmasters # mmasters is the login id for the machines
verbose=0
showmachinenames=1

The last thing we need to do is set up passwordless ssh for all the machines in our group file. Once that's done, we can start using dsh. Go ahead and give it a test drive:
dsh -g testMachines 'uname -a'
The -g argument tells dsh which group file we want to use.

No comments: