Broadcast a Command with SSH

July 18, 2004

Use ssh to broadcast a command to a list of hosts given that you've already setup ssh keys and the login is automatic.

# This is a sample script to "broadcast" a command via ssh to a set of computers
# each server to distribute to
DHOSTS="host1 host2 host3";
# Loop through each server and distributes each file
for DHOST in $DHOSTS; do
	echo "Working on host $DHOST with command $1";
	ssh $DHOST $1;

Related Posts


Comment May 5, 2010 by anonymous
This is not broadcast since there is no concurrency guarantee.
Comment May 6, 2014 by live chat
Yeah, Deffo not broadcast.. More of a do one, then the next etc.. I suppose you could child of the processes? We do something similar on our platform where we farm out simple commands to all servers quickly. Would be nice to have a proper broadcast method though. Any ideas?