forked from greearb/lanforge-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_group_matching.sh
executable file
·67 lines (57 loc) · 1.4 KB
/
create_group_matching.sh
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
#!/bin/bash
usage="$0 <manager> <group-name> <endp-name-prefix>"
if [[ x$1 = x ]]; then
echo "Please provide lanforge manager hostname or ip"
echo $usage
exit 1
fi
if [[ x$2 = x ]]; then
echo "Please provide a group name"
echo $usage
exit 1
fi
if [[ x$3 = x ]]; then
echo "Please provide an endpoint name prefix"
echo $usage
exit 1
fi
# query for endpoints maching prefix
if [ -f /tmp/endp.$$ ]; then
rm -f /tmp/endp.$$
fi
./lf_firemod.pl --mgr $1 --quiet yes --action list_endp > /tmp/endp.$$
lines=`wc -l < /tmp/endp.$$`
if [ $lines -lt 1 ]; then
echo "Unable to see any endpoints"
exit 1
fi
declare -A names
while read line; do
hunks=($line)
endp="${hunks[1]}"
endp=${endp/]/}
endp=${endp/[/}
if [[ $endp = D_* ]]; then
continue
fi
# if name lacks a -A/B ending, it is prolly generic and the cx begins with CX_
if [[ $endp = *-A ]] || [[ $endp = *-B ]]; then
cxname=${endp%-A}
cxname=${cxname%-B}
else
cxname="CX_${endp}"
fi
if [[ $cxname = $3* ]] || [[ $cxname = CX_$3* ]]; then
names[$cxname]=1
fi
done < /tmp/endp.$$
if [ ${#names[@]} -lt 1 ]; then
echo "No connections start with $3"
exit 1
fi
echo "Creating group $2"
./lf_firemod.pl --mgr $1 --quiet 1 --cmd "add_group '$2'"
for n in ${!names[@]}; do
echo "adding connection $n to '$2'"
./lf_firemod.pl --mgr $1 --quiet 1 --cmd "add_tgcx '$2' '$n'"
done