-
Notifications
You must be signed in to change notification settings - Fork 5
/
ssh-all
executable file
·63 lines (55 loc) · 1.23 KB
/
ssh-all
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
#!/bin/bash
[ -z "$2" ] && {
echo "This script executes commands and copy files to all nodes"
echo "connected to a network interface (link-local connection)."
echo "It uses IPv6 to discover the IPv6 link local addresses"
echo ""
echo "$0 <interface> <-c|-cb|-f> [parameters]"
echo " -c -> execute command"
echo " -cb -> execute command in background"
echo " -f -> copy file"
exit 0
}
I="$1"
shift
T="$1"
shift
TMP="/tmp/wibed"
echo "Discovering nodes..."
ping6 ff02::2%$I -c 5 -i 1 -s 16 | grep "^24" > $TMP.nodes.tmp
cat $TMP.nodes.tmp | awk '{print $4}' | sed s/":$"//g | sort -u > $TMP.nodes
echo "-------------------------"
cat $TMP.nodes
echo "-------------------------"
echo
[ "$T" == "-c" ] && {
C="$@"
echo "Executing command $C"
for IP in $(cat $TMP.nodes)
do
echo "-------------------------"
echo " $IP"
echo "-------------------------"
ssh -t $IP%$I $@
done
}
[ "$T" == "-cb" ] && {
C="$@"
echo "Executing background command $C"
for IP in $(cat $TMP.nodes)
do
echo "-------------------------"
echo " $IP"
echo "-------------------------"
ssh -ft $IP%$I $@
done
}
[ "$T" == "-f" ] && {
O="$1"
D="$2"
echo "Copying file $O into $D"
for IP in $(cat $TMP.nodes)
do
scp -r $O [$IP%$I]:$D
done
}