#!/bin/bash # # Execute commands on multiple nodes. # # Issue commands with pssh # See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=549117 function mass_pssh { hydra_set_tmpfile nodes hydra $HYDRA nodes > $TMPWORK parallel-ssh -h $TMPWORK -p 4 $COMMAND hydra_unset_tmpfile $TMPWORK } # Issue commands with a for loop function mass_loop { for node in $NODES; do echo "Issuing $COMMAND on multiple nodes..." echo "Connecting to $node..." $HYDRA_CONNECT $node sudo $COMMAND done } # Load source $APP_BASE/lib/hydra/functions || exit 1 hydra_config_load # Command line arguments BASENAME="`basename $0`" COMMAND="$*" # Initial node list NODES="`hydra $HYDRA nodes`" # Validation if [ "$BASENAME" == "mass-update" ]; then COMMAND="aptitude update" elif [ "$BASENAME" == "mass-upgrade" ]; then COMMAND="aptitude safe-upgrade -y" elif [ "$BASENAME" == "mass-web" ]; then NODES="`hydra $HYDRA nodes web`" fi # Execute commands in hosts mass_loop $COMMAND