2 ################################################################################
5 # Description: Runs an arbitrary command on all machines
6 # Author: Andrew@DeFaria.com
7 # Created: Fri Apr 30 14:17:40 PDT 1999
9 # Modifications:Added trapping of INT so that you can abort a non-responding
12 # (c) Copyright 2001, Andrew@DeFaria.com, all rights reserved
14 ################################################################################
15 # Set me to command name
18 if [ -f ~/.rc/set_colors ]; then
19 source ~/.rc/set_colors
23 adm_base=${adm_base:-/opt/clearscm}
26 machines=${machines:-$adm_base/data/machines}
28 if [ "$1" = "-f" ]; then
34 if [ "$1" = "-r" ]; then
39 if [ ! -f $machines ]; then
40 echo "Unable to find $machines file!"
45 echo "${machines[i]}:$cmd interrupted"
46 echo -e "$RED(A)bort$NORMAL $me or $YELLOW(C)ontinue$NORMAL with next machine? \c"
48 typeset -l response=$response
52 echo "Aborting $me..."
56 echo "Continuing on with the next machine..."
59 # Build up data arrays. Note this is done because if we ssh while in a pipe
60 # Sun will not allow a simple ssh with no command (boo!)
61 # Column 1 Machine name
64 # Column 4 ClearCase Version (if applicable)
65 # Column 5 Owner (if known)
66 # Column 6 Usage (if known)
69 declare -i nbr_of_machines=0
71 while read machine model os cc owner usage; do
72 machines[nbr_of_machines]=$machine
73 let nbr_of_machines=nbr_of_machines+1
74 done < <(grep -v ^# $machines)
76 if [[ -z "$@" ]]; then
77 cmd="# ${YELLOW}<- ssh into machine$NORMAL"
82 # This loop executes the command
85 while [ $i -lt $nbr_of_machines ]; do
86 export currmachine=${machines[i]}
87 # Execute command. Note if no command is given then the effect is to
88 # ssh to each machine.
89 echo -e "${B_AQUA}${machines[i]}$NORMAL\c"
92 if [ "$root_ssh" = "true" ]; then
93 ssh ${machines[i]} -n -l root "$cmd"
95 ssh ${machines[i]} -n "$cmd"
98 if [ "$root_ssh" = "true" ]; then
99 ssh ${machines[i]} -l root