Re: "parallelizing" a script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 16:11 25 Nov 2003, lasalle@xxxxxxxx <lasalle@xxxxxxxx> wrote:
| I have script that I use to effect the same change on all the computers I look after.  
| It looks like this pretty much:
| 
| printf "machine1:\n"
| ssh machine1 $1
| printf "machine2:\n"
| ssh machine2 $1
| printf "machine3:\n"
| ssh machine3 $1
| printf "machine4:\n"
| ssh machine4 $1
| ..
| 
| If the operation is complex, it can take some time to go through all the machines 
| serially.  I've placed an & after the commands so that the script stops waiting for 
| each command to complete, but now the print statements are all but useless to help 
| me trace errors back to machines.  Can someone recommend a way in which I can 
| keep the speed and the meaningful output?  Something simpler than sending 
| STDOUT and STDERR to a different file for each machine?

Sure.

	for host in blah blah blah ...
	do
	  ssh -f "$host" "command here ..." 2>&1 | sed "s/^/$host: /" &
	done
	wait

If you're using an ssh-agent to authenticate, put a "sleep 1" in the
loop - ssh-agent does no locking, and some sshes will fail if they all
hammer the agent at once - you need to stagger then slightly.

See:

	http://www.cskk.ezoshosting.com/cs/scripts/sshall

for an over engineered example I use a lot.

Cheers,
-- 
Cameron Simpson <cs@xxxxxxxxxx> DoD#743
http://www.cskk.ezoshosting.com/cs/

The old day of Perl's try-it-before-you-use-it are long as gone.  Nowadays
you can write as many as 20..100 lines of Perl without hitting a bug in the
perl implementation.    - Ilya Zakharevich <ilya@xxxxxxxxxxxxxxxxxxx>,
                          in the perl-porters list, 22sep1998


-- 
redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list

[Index of Archives]     [CentOS]     [Kernel Development]     [PAM]     [Fedora Users]     [Red Hat Development]     [Big List of Linux Books]     [Linux Admin]     [Gimp]     [Asterisk PBX]     [Yosemite News]     [Red Hat Crash Utility]


  Powered by Linux