dsh (Dancer’s Shell / Distributed Shell) and you

dsh is an awesome tool for administering pools of servers where you would just want to run the same few commands on each one. I run Mac OSX locally, so I’ll write the article from that perspective:

Install DSH on a Mac

First and foremost, you need to install dsh. The downloads page for the project is a nightmare (http://www.netfort.gr.jp/~dancer/software/downloads/list.cgi), but you basically want the latest version of libdshconfig and dsh. At the time of this writing, that would be 0.20.13 and 0.25.9 respectively.

I just dropped them into /tmp for the time being:

Then go through the normal install from source process, starting with libdshconfig

now you should be able to run dsh and have it return an error that no machine was specified:

Configuring DSH

You will want to setup RSA keys for your user on each of the machines that you want to log in to remotely so that you are not prompted for a password. (This is outside the scope of this article, there are about a gazillion different articles online that will teach that). Once the keys are in place, you will want to create group files. You will need to mkdir -p ~/.dsh/group and then create a text file in the group directory that lists the machines you want to connect to. Here is an example:

This sets the user and the host that you want in the “web” group.

Next up is a very important configuration change. dsh wants to use rsh by default instead of ssh. You will need to edit /usr/local/etc/dsh.conf as an Administrator to change that. Just change the line:

to read:

Save the file, and you are ready to go.

Actually using DSH

Ok, now for the magic. Assuming you have a group named ‘web’, you could run:

This will return the results of uname -a for each server. The -c flag does it concurrently instead of going to each machine one at a time. The -M flag tells it to list the machine name by the response.

Other stuff

I prefer to always see the machine name, so instead of always specifying -M, I created a new file at ~/,dsh/dsh.conf and included the line “showmachinenames=1”. You can set other options here too. For example, say you use a non standard ssh port. You could specify on the command line with -o:

OR, you can set dsh to always use a different port by adding the line “remoteshellopt=-p 2222” to your configuration file.

Other sources if my article didn’t make sense:

Check out Racker Hacker’s post: http://rackerhacker.com/2010/01/20/crash-course-in-dsh/

  1. Excellent Josh!

    As an FYI, macports also includes dsh. First install the macports dmg, then a sudo port install dsh will download, compile, and install dsh. The config file will be located in /opt/local/etc/dsh.conf after that.

    –chris

  2. Should also point out, that .dsh/group as well as /opt/local/etc/group will both work for adding dsh groups.

    –chris

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">