Created
April 9, 2014 16:04
-
-
Save nestoru/10286770 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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