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 |
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
# pure command line | |
$ ./runInHosts.sh "user@server1.sample.com user@server2.sample.com user@server3.sample.com user@server4.sample.com user@server5.sample.com" date | |
user@server5.sample.com: Fri Jul 12 11:45:02 EDT 2013 | |
user@server2.sample.com: Fri Jul 12 11:45:02 EDT 2013 | |
user@server4.sample.com: Fri Jul 12 11:45:02 EDT 2013 | |
user@server3.sample.com: Fri Jul 12 11:45:02 EDT 2013 | |
user@server1.sample.com: Fri Jul 12 11:45:02 EDT 2013 | |
# using a file | |
$ cat hosts.txt | |
user@server1.sample.com | |
user@server2.sample.com | |
user@server3.sample.com | |
user@server4.sample.com | |
user@server5.sample.com | |
$ ./runInHosts.sh hosts.txt date | |
user@server5.sample.com: Fri Jul 12 11:45:02 EDT 2013 | |
user@server2.sample.com: Fri Jul 12 11:45:02 EDT 2013 | |
user@server4.sample.com: Fri Jul 12 11:45:02 EDT 2013 | |
user@server3.sample.com: Fri Jul 12 11:45:02 EDT 2013 | |
user@server1.sample.com: Fri Jul 12 11:45:02 EDT 2013 |
No comments:
Post a Comment