Skip to content

Instantly share code, notes, and snippets.

@nestoru
Created April 9, 2014 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nestoru/10286770 to your computer and use it in GitHub Desktop.
Save nestoru/10286770 to your computer and use it in GitHub Desktop.
#!/bin/bash -e
# runInHosts.sh
# @author: Nestor Urquiza
# @created: 20130712
USAGE="Usage: `basename $0` <clusterNodes[user@host space delimited list or a path to a file comntaining the list]> <command>"
if [ $# -ne "2" ]; then
echo $USAGE
exit 1
fi
function run() {
echo "$1: $(ssh $1 $2)"
}
clusterNodes=$1
command=$2
#If not a list then try path
if [[ ! "$clusterNodes" =~ ^.*@ ]]
then
if [ ! -f "$clusterNodes" ]
then
echo $USAGE
exit 1
fi
clusterNodes=`cat $clusterNodes`
fi
for host in $clusterNodes; do
run $host "$command" &
done
wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment