Initial add of defaria.com
[clearscm.git] / defaria.com / Computers / code / adm / bin / allmach
1 #!/bin/bash
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 # Source /etc/site_parms
19 if [ -f /etc/site_parms ]; then
20   . /etc/site_parms
21 else
22   echo "$me: WARNING: /etc/site_parms does not exist!"
23 fi
24
25 # Set adm_base
26 adm_base="$SITE_TOOLS_PATH/adm"
27
28 # Set adm_fpath
29 adm_fpath=${adm_fpath:-$adm_base/functions}
30
31 # Source functions
32 . $adm_fpath/common
33
34 # Set currmachine
35 currmachine=
36
37 if [ "$1" = "-r" ]; then
38   root_remsh=true
39   shift
40 fi
41
42 function trap_intr {
43   echo "$currmachine:$cmd interrupted"
44   echo -e "(A)bort $me or (C)ontinue with next machine? \c"
45   read response
46   response=$(echo $response | tr [:upper:] [:lower:])
47
48   case "$response" in
49     a|abort)
50       display "Aborting $me..."
51       exit
52     ;;
53   esac
54   display "Continuing on with the next machine..."
55 } # trap_intr
56
57 # Gather all machines into the machines variable so we can
58 # use a for loop
59 net view        | 
60   grep -e '\\'  | 
61   cut -f3 -d\\  | 
62   cut -f1 -d' ' |
63   tr [:upper:] [:lower:] > /tmp/$me.$$
64
65 machines=$(cat /tmp/$me.$$);
66 rm -f /tmp/$me.$$
67
68 # This loop executes the command
69 trap trap_intr INT
70
71 for machine in $machines; do
72   currmachine=$machine
73   # Execute command. Note if no command is given then the effect is to
74   # rlogin to each machine.
75   echo "$machine:$@"
76   cmd="$@"
77   if [ $# -gt 0 ]; then
78     if [ "$root_remsh" = "true" ]; then
79       rsh $machine -nl root "$cmd"
80     else
81       rsh $machine -n "$cmd"
82     fi
83   else
84     if [ "$root_remsh" = "true" ]; then
85       rsh $machine -nl root
86     else
87       echo "Executing rlogin $machine"
88       rlogin $machine
89     fi
90   fi
91 done