{ 9 comments… read them below or add one }

1 Anonymous 12.28.05 at 7:15 pm
2 Michael 12.28.05 at 8:31 pm

If you want to fully parallelize the script you can wrap the ssh command in parentheses in order to execute in a subshell, I believe. That way the script doesn’t wait for the program to finish. I use this to dynamically test all the workstations in my lab (~150) to see which ones are up and running, so I can generate a machine list for a distributed MPICH program.

3 Anonymous 12.28.05 at 8:55 pm

Very nice script. I use(d?) to manually write a “for” loop every time I need to run the same command on multiple hosts.
I’ve just modified your sample script, declaring another variable (COMMAND=$@) to use instead of “w”, so I can run
./dsh cat /etc/hosts to get the content of all servers’ /etc/hosts in my mailbox.

4 WikiGeeiki 12.23.06 at 11:29 pm

Excellent article! Thank you.

5 nfo 09.10.08 at 8:14 am

Hi, nice script, simple and functionally!
another simialar solution is http://freshmeat.net/projects/dsh/
dsh can start a command parallel and serial, witch is a small advantage, but never mind.

best regards
andreas

6 Albert 12.30.08 at 7:47 pm

Great script, easy to use and understand. Thanks.

7 Boby Thomas 03.24.09 at 10:49 am

Nice script….thanks

8 Nitn G 10.09.09 at 5:30 pm

i tested this script found not working when one of host is down ssh command does not proceed to next host

please help

Nitin

9 Jidnesh I. Bhogare 01.12.10 at 6:43 am

Hi, the script is really help ful!! Thanks for this. I want to add one small things for the administrators / developers who want to execute a command only on the remote machine via ssh + shell script e.g ssh test@192.168.0.2 ’service httpd status’ ….if some one want to change the single quoted parameter…he has to defined that much variable and called each variable one by one as per his desire to form expected command…check this code

#!/bin/sh
INPUT="service"
I2=$1
#I2="httpd"
I3=$2
#I3="stop"
for I in $INPUT
do
echo -e "----------------------------------------------\n";
for ip1 in $I2
do
for ip2 in $I3
do
ssh root@192.168.0.2 $I $ip1 $ip2
done
done
echo -e "----------------------------------------------\n";
done

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous post:

Next post: