1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
#! /bin/sh
# executes a command on all hosts which are return by all_hosts
# T. Lange; jan 2000 Institut fuer Informatik, Uni Koeln
# A. Menze und F. Möllers; März 2003 Institut für Informatik, Uni Köln
# Add usage and exclude function
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
usage() {
cat <<EOF
Usage: rshall [option] arguments
rshall with given arguments executes those arguments on all alive
hosts of the network
options:
-h print this message.
-e host[,host ...] exclude this comma sperated list of machines
examples:
rshall date
rshall -e rubens,frueh,suenner,[...] date
EOF
exit 0
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
list() {
if [ -n "$nohosts" ] ; then
echo
echo The command will not be executed on the following hosts because
echo they are down: $nohosts
# echo You have 5 seconds to stop by typing "control c"
sleep 5s
fi
for h in $hosts; do
echo ''
echo ''
echo '***** '$h:
rsh $h "$@"
done
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
typos() {
all=`prtnetgr allhosts`
for e in $ehosts; do
exists=0
for a in $all; do
if [ $e = $a ] ; then
exists=1
fi
done
if [ $exists = 0 ] ; then
error=1
error_hosts="$error_hosts $e"
fi
done
if [ $error = 1 ] ; then
echo +++ !!! +++ ATTENTION PLEASE +++ !!! +++
echo
echo The following machine\(s\) does not exist: $error_hosts
echo
exit 1
fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
exclude() {
ehosts=`echo $* | sed "s/,/ /g"`
error=0
typos
for h in $allhosts; do
einf=1
for e in $ehosts; do
if [ $h = $e ] ; then
einf=0
fi
done
if [ $einf = 1 ] ; then
dhosts="$dhosts $h"
fi
done
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
eflag=0
while getopts e:h a
do
case "$a" in
h) usage;;
e) eflag=1;;
*) usage;;
esac
done
[ -z "$1" ] && usage;
allhosts=`all_hosts`
nohosts=`all_hosts -n`
if [ $eflag = 0 ]; then
hosts=$allhosts
else
exclude $OPTARG
shift `expr $OPTIND - 1`
hosts=$dhosts
fi
list "$*"
|