4 ################################################################################
7 # Description: Runs an arbitrary command on all machines
8 # Author: Andrew@DeFaria.com
9 # Created: Fri Apr 30 14:17:40 PDT 1999
10 # Language: Bash Shell
11 # Modifications:Added trapping of INT so that you can abort a non-responding
14 # (c) Copyright 2001, Andrew@DeFaria.com, all rights reserved
16 ################################################################################
17 # Set me to command name
20 if [ -f ~/.rc/set_colors ]; then
21 source ~/.rc/set_colors
25 adm_base=${adm_base:-/opt/clearscm}
28 machines=${machines:-$adm_base/data/machines}
30 if [ "$1" = "-f" ]; then
36 if [ "$1" = "-r" ]; then
41 if [ ! -f $machines ]; then
42 echo "Unable to find $machines file!"
47 echo "${machines[i]}:$cmd interrupted"
48 echo -e "$RED(A)bort$NORMAL $me or $YELLOW(C)ontinue$NORMAL with next machine? \c"
50 typeset -l response=$response
54 echo "Aborting $me..."
58 echo "Continuing on with the next machine..."
61 # Build up data arrays. Note this is done because if we ssh while in a pipe
62 # Sun will not allow a simple ssh with no command (boo!)
63 # Column 1 Machine name
66 # Column 4 ClearCase Version (if applicable)
67 # Column 5 Owner (if known)
68 # Column 6 Usage (if known)
71 declare -i nbr_of_machines=0
72 #sed -e "/^#/d" $machines |
73 while read machine; do
74 machines[nbr_of_machines]=$machine
75 let nbr_of_machines=nbr_of_machines+1
76 done < <(grep -v ^# $machines)
78 if [[ -z "$@" ]]; then
79 cmd="# ${YELLOW}<- ssh into machine$NORMAL"
84 # This loop executes the command
87 while [ $i -lt $nbr_of_machines ]; do
88 export currmachine=${machines[i]}
89 # Execute command. Note if no command is given then the effect is to
90 # ssh to each machine.
91 echo -e "${CYAN}${machines[i]}$NORMAL\c"
94 if [ "$root_ssh" = "true" ]; then
95 ssh ${machines[i]} -n -l root "$cmd"
97 ssh ${machines[i]} -n "$cmd"
100 if [ "$root_ssh" = "true" ]; then
101 ssh ${machines[i]} -l root