-
Notifications
You must be signed in to change notification settings - Fork 0
/
ap-move.sh
executable file
·213 lines (142 loc) · 5.38 KB
/
ap-move.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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/bin/bash
#
# The purpose of this script is to automate Cisco Access Point moving
# The script identifies the list of AP's, as well
# and then pushes the changes to the controllers one by one.
#
# # # # DECLARE VARIABLES AND FILE PATHS # # # #
# # # # # # # # # # # # # # # # # # # # # # # # #
CONFIGLOG="$HOME/Documents/wireless-scripts/logs/configlog-`date +%m-%d-%Y`.log"
CONTROLLERLIST="$HOME/Documents/wireless-scripts/old-controller-list.txt"
APLISTPATH="$HOME/Documents/wireless-scripts/ap-lists/"
SNMPOPTIONS="-v3 -a SHA -A SUP3R-S3CR3T! -l authNoPriv -u neteng -Ob"
PS3="Select a controller: "
# # # # # # # # # # # # # # # # #
# # # # READ AP List # # # #
READAPLIST(){
clear
printf "\nPlease enter the list of AP's to be moved:\n"
printf "`ls $APLISTPATH`\n"
printf "--------------------------------------\n> "
read APLIST
if [ -f $APLISTPATH$APLIST ]
then
printf "\nAP List = \"./ap-lists/$APLIST\" (confirmed)\n"
else
printf "\nAP list = \"./ap-lists/$APLIST\" (does not exist!)\n"
printf "Aborting...\n\n"
exit
fi
}
# # # # CHECK WHICH CONTROLLER AP IS REGISTERED TO # # # #
# AND READ IN $RADIOMAC AND $REGCONTROLLER #
FINDAP(){
printf "--------------------------------------------------\n\n"
printf "====[ Finding AP on Controllers... ]====\n\n"
for CONTROLLERS in `cat $CONTROLLERLIST`; do
SEARCH=$(snmpwalk $SNMPOPTIONS $CONTROLLERS \
bsnAPName | grep $NAME\")
if [[ $SEARCH = *$NAME* ]]
then
printf "!!!! $NAME FOUND on Controller $CONTROLLERS !!!!\n"
REGCONTROLLER=$CONTROLLERS
RADIOMAC=$(sed -n 's/.*bsnAPName.\(.*\)=.*/\1/p' <<< "$SEARCH")
CURCONTROLLER1=$(snmpwalk $SNMPOPTIONS $REGCONTROLLER \
bsnAPPrimaryMwarName | grep $RADIOMAC | cut -d\" -f2 )
CURCONTROLLER2=$(snmpwalk $SNMPOPTIONS $REGCONTROLLER \
bsnAPSecondaryMwarNAme | grep $RADIOMAC | cut -d\" -f2)
break
else
printf "$NAME not found on Controller $CONTROLLERS\n"
fi
done
# printf $RADIOMAC\n
# printf $REGCONTROLLER\n
}
# # # # VERIFY CHANGES # # # #
VERIFY(){
printf "\n\n\n=====[ Current AP Information ]=====\n"
printf "AP Name: $NAME\n"
printf "Registered to Controller: $REGCONTROLLER\n"
printf "Current Primary Controller: $CURCONTROLLER1\n"
printf "Current Secondary: $CURCONTROLLER2\n"
printf "AP SNMP Identifier: $RADIOMAC\n"
printf "\n\n=====[ Configuraiton Changes ]=====\n"
printf "New Primary Controller: $CONTROLLER1\n"
printf "New Secondary Controller: $CONTROLLER2\n"
printf "\n\nPress Cntl-Z to quit in the next 5 seconds if this is not correct!\n"
for i in {5..1};do printf "$i, " && sleep 1; done
}
# # # # IMPLEMENT AND LOG CHANGES # # # #
IMPLEMENT(){
printf "\n\n====[ Implementing changes... ]====\n"
printf "\n\n===[ $NAME ]===\n\n" | tee -a $CONFIGLOG
OUTPUT=$(snmpset $SNMPOPTIONS $REGCONTROLLER \
bsnAPPrimaryMwarName.$RADIOMAC s $CONTROLLER1 \
bsnAPSecondaryMwarName.$RADIOMAC s $CONTROLLER2)
printf "$OUTPUT\n" | tee -a $CONFIGLOG
}
# # # # WAIT FOR AP TO RE-REGISTER # # # #
WAITFORAP(){
printf "\n\n====[ Waiting for AP to re-register to new Primary Controller... ]====\n"
while [ "$APCHECK" != "TRUE" ]; do
STATUS=$(snmpwalk $SNMPOPTIONS $CONTROLLER1 \
bsnAPName | grep $NAME\")
if [[ $STATUS = *$NAME* ]]
then
printf "\n\n!!!! $NAME is now registered to Controller $CONTROLLER1 !!!!\n\n"
printf "Now waiting 3 seconds to see if AP Needs to download code...\n"
for i in {3..1};do printf "$i, " && sleep 1; done
DOWNLOAD=$(snmpwalk $SNMPOPTIONS $CONTROLLER1 \
bsnAPOperationStatus.$RADIOMAC)
while [[ $DOWNLOAD != *associated* ]]; do
printf "\n\nAP Downloading updated Firmware and will reboot...\n"
printf "This can take several minutes, please Wait...\n\n"
for i in {10..1};do printf "$i, " && sleep 1; done
DOWNLOAD=$(snmpwalk $SNMPOPTIONS $CONTROLLER1 \
bsnAPOperationStatus.$RADIOMAC)
done
printf "\n\nAP $NAME Ready to go!\n"
APCHECK="TRUE"
else
printf "\n\n$NAME not registered on Controller $CONTROLLER1 yet.\n"
printf "Waiting 10 seconds and checking again...\n"
APCHECK="FALSE"
for i in {10..1};do printf "$i, " && sleep 1; done
fi
done
}
# # # # CLEAR SCREEN AND BEGIN SCRIPT # # # #
# # # # # # # # # # # # # # # # # # # # # # #
clear
printf "=====[ AP Moving Script ]=====\n\n\n"
printf "This script is meant to be used to move many\nAccess Points between two controllers.\n\n\n"
# # # # Read AP List with READAPLIST Function # # # #
READAPLIST
# # # # GATHER AP INFORMATION # # # #
printf "\n\nPlease select the Primary Controller you would like these APs to register to:\n"
select CONTROLLER1 in `cat $CONTROLLERLIST`; do
printf "You have selected $CONTROLLER1\n"
break
done
# CONTROLLER1="AMH5508-HLT-1"
printf "\n\nPlease select the Secondary Controller you would like these APs to register to:\n"
select CONTROLLER2 in `cat $CONTROLLERLIST`; do
printf "You have selected $CONTROLLER2\n"
break
done
# CONTROLLER2="AMH5508-HLT-2"
# # # # Execute # # # #
for NAME in `cat $APLISTPATH$APLIST`; do
# # # # FIND AP WITH FIND FUNCTION # # # #
FINDAP
# # # # VERIFY INFORMATION WITH VERIFY FUNCTION # # # #
VERIFY
# # # # IMPLEMENT CHANGES WITH IMPLEMENT FUNCTION # # # #
IMPLEMENT
# # # # WAIT FOR AP TO REGISTER TO NEW CONTROLLER # # # #
APCHECK="FALSE"
WAITFORAP
done
printf "\n====[ ALL APs have been migrated ]====\n====[ EXITING! ]====\n"
exit