Removed /usr/local from CDPATH
[clearscm.git] / clients / HP / bin / allmach
1 #!/bin/ksh
2 ################################################################################
3 #
4 # File:         allmach
5 # Description:  Runs an arbitrary command on all machines
6 # Author:       Andrew@DeFaria.com
7 # Created:      Fri Apr 30 14:17:40 PDT 1999
8 # Language:     Korn Shell
9 # Modifications:Added trapping of INT so that you can abort a non-responding
10 #               machine.
11 #
12 # (c) Copyright 2001, Andrew@DeFaria.com, all rights reserved
13 #
14 ################################################################################
15 # Set me to command name
16 me=$(basename $0)
17
18 # Set adm_base
19 adm_base=${adm_base:-$HOME/adm}
20
21 # Set adm_fpath
22 adm_fpath=${adm_fpath:-$adm_base/functions}
23
24 # Source functions
25 . $adm_fpath/common
26
27 # Set machines
28 machines=${machines:-$adm_base/data/machines}
29
30 if [ "$1" = "-f" ]; then
31   shift
32   machines="$1"
33   shift
34 fi
35
36 if [ "$1" = "-r" ]; then
37   root_remsh=true
38   shift
39 fi
40
41 if [ ! -f $machines ]; then
42   error "Unable to find $machines file!" 1
43 fi
44
45 function trap_intr {
46   display "${machines[i]}:$cmd interrupted"
47   display "(A)bort $me or (C)ontinue with next machine? \c"
48   read response
49   typeset -l response=$response
50
51   case "$response" in
52     a|abort)
53       display "Aborting $me..."
54       exit
55     ;;
56   esac
57   display "Continuing on with the next machine..."
58 } # trap_intr
59
60 # Build up data arrays. Note this is done because if we remsh while in a pipe
61 # Sun will not allow a simple remsh with no command (boo!)
62 # Column 1 Machine name
63 # Column 2 Model
64 # Column 3 OS Version
65 # Column 4 ClearCase Version (if applicable)
66 # Column 5 Owner (if known)
67 # Column 6 Usage (if known)
68 oldIFS=$IFS
69 IFS=":"
70 integer nbr_of_machines=0
71 sed -e "/^#/d" $machines |
72   while read machine model osversion ccversion owner phone usage location;
73 do
74   machines[nbr_of_machines]=$machine
75   models[nbr_of_machines]=$model
76   #osversions[nbr_of_machines]=$osversion
77   #ccversions[nbr_of_machines]=$ccversion
78   #owners[nbr_of_machines]=$owner
79   #phones[nbr_of_machines]=$phone
80   #usages[nbr_of_machines]=$usage
81   #locations[nbr_of_machines]=$location
82   let nbr_of_machines=nbr_of_machines+1
83 done
84 IFS="$oldIFS"
85
86 # This loop executes the command
87 trap trap_intr INT
88 integer i=0
89 while [ $i -lt $nbr_of_machines ]; do
90   export currmachine=${machines[i]}
91   # Execute command. Note if no command is given then the effect is to
92   # rlogin to each machine.
93   print -u2 "${machines[i]}\c"
94   print -u2 ":$@"
95   cmd="$@"
96   if [ $# -gt 0 ]; then
97     if [ "$root_remsh" = "true" ]; then
98       remsh ${machines[i]} -n -l root "$cmd"
99     else
100       remsh ${machines[i]} -n "$cmd"
101     fi
102   else
103     if [ "$root_remsh" = "true" ]; then
104       remsh ${machines[i]} -l root
105     else
106       remsh ${machines[i]}
107     fi
108   fi
109   let i=i+1
110 done
111 trap - INT