{ 10 comments… read them below or add one }

1 Anonymous December 28, 2005 at 7:15 pm
2 Michael December 28, 2005 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.

Reply

3 Anonymous December 28, 2005 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.

Reply

4 WikiGeeiki December 23, 2006 at 11:29 pm

Excellent article! Thank you.

Reply

5 nfo September 10, 2008 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

Reply

6 Albert December 30, 2008 at 7:47 pm

Great script, easy to use and understand. Thanks.

Reply

7 Boby Thomas March 24, 2009 at 10:49 am

Nice script….thanks

Reply

8 Nitn G October 9, 2009 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

Reply

9 Jidnesh I. Bhogare January 12, 2010 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

Reply

10 tepisi December 23, 2010 at 12:14 pm

But, how to execute remote self made shell script via ssh?

Reply

Leave a Comment

Tagged as: , , , , , , , , , , , , , ,

Previous post:

Next post: