slaves.sh 902 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/bash
  2. #
  3. # Run a shell command on all slave hosts.
  4. #
  5. # Environment Variables
  6. #
  7. # HADOOP_SLAVES File naming remote hosts. Default is ~/.slaves
  8. ##
  9. usage="Usage: slaves.sh command..."
  10. # if no args specified, show usage
  11. if [ $# -le 0 ]; then
  12. echo $usage
  13. exit 1
  14. fi
  15. # resolve links - $0 may be a softlink
  16. this="$0"
  17. while [ -h "$this" ]; do
  18. ls=`ls -ld "$this"`
  19. link=`expr "$ls" : '.*-> \(.*\)$'`
  20. if expr "$link" : '.*/.*' > /dev/null; then
  21. this="$link"
  22. else
  23. this=`dirname "$this"`/"$link"
  24. fi
  25. done
  26. # the root of the Hadoop installation
  27. HADOOP_HOME=`dirname $this`/..
  28. if [ -f "$HADOOP_HOME/conf/hadoop-env.sh" ]; then
  29. source ${HADOOP_HOME}/conf/hadoop-env.sh
  30. fi
  31. if [ "$HADOOP_SLAVES" = "" ]; then
  32. export HADOOP_SLAVES=$HADOOP_HOME/conf/slaves
  33. fi
  34. for slave in `cat $HADOOP_SLAVES`; do
  35. ssh -o ConnectTimeout=1 $slave "$@" \
  36. 2>&1 | sed "s/^/$slave: /" &
  37. done
  38. wait