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:
cd /tmp wget http://www.netfort.gr.jp/~dancer/software/downloads/libdshconfig-0.20.13.tar.gz wget http://www.netfort.gr.jp/~dancer/software/downloads/dsh-0.25.9.tar.gz
Then go through the normal install from source process, starting with libdshconfig
cd /tmp tar -zxvf libdshconfig-0.20.13.tar.gz cd libdshconfig-0.20.13 ./configure make sudo make install
cd /tmp tar -zxvf dsh-0.25.9.tar.gz cd dsh-0.25.9 ./configure make sudo make install
now you should be able to run dsh and have it return an error that no machine was specified:
josh.prewitt$ dsh dsh: no machine specified
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:
josh.prewitt$ pwd /Users/josh.prewitt/.dsh/group
josh.prewitt$ cat web email@example.com firstname.lastname@example.org email@example.com
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:
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:
dsh -c -g web -M 'uname -a'
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.
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:
dsh -c -g web -o "-p 2222" 'uname -a'
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/