Last active
May 24, 2020 05:33
-
-
Save jfeilbach/355da68d048ef08ecbcea48f14b969cc to your computer and use it in GitHub Desktop.
manually readopt all switches and access points on LAN if controller lost
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# version 1.2 | |
# removed 192.168.1.11 | |
# removed 192.168.1.14 | |
# Readopt UniFi devices by UniFi controller | |
# The set-inform command is an alias on the remote host. Obviously we don't have the same env as a remote ssh login. The same is true for the info command. | |
# set-inform='mca-cli-op set-inform' | |
# info='mca-cli-op info' | |
addr='192.168.1.' | |
inf_host="192.168.1.42" | |
inf_port="8080" | |
inform=http://${inf_host}:${inf_port}/inform | |
wait='10' | |
cmd='mca-cli-op' | |
# Reset | |
NC='\033[0m' # No color | |
# Regular Colors | |
Red='\033[0;31m' # Red | |
Green='\033[0;32m' # Green | |
Yellow='\033[0;33m' # Yellow | |
White='\033[0;37m' # White | |
echo -e "\nThe UniFi controller is set to use ${inform}\n" | |
for x in {2..10} {12..13} ; do | |
host=$(ssh ${addr}${x} ${cmd} info) | |
cur_host=$(echo $host | awk '{ print $11 " " $12 }') | |
cur_host_ip=$(echo $host | awk '{ print $8 " " $9 " " $10 }') | |
echo -e "\n=======================================" | |
echo -e "${White}${cur_host}${NC}" | |
echo -e "${Yellow}${cur_host_ip}${NC}" | |
ssh ${addr}${x} ${cmd} set-inform ${inform} | |
done | |
for x in {2..10} {12..13} ; do | |
chk_cmd=$(ssh ${addr}${x} ${cmd} info | grep 'Status' | awk '{ print $3 }' | tr -d '()') | |
host=$(ssh ${addr}${x} ${cmd} info) | |
cur_host=$(echo $host | awk '{ print $12 }') | |
cur_host_ip=$(echo $host | awk '{ print $8 " " $9 " " $10 }') | |
if [[ "${chk_cmd}" == "${inform}" ]]; then | |
echo -e "${Green}Success.${NC} Device ${White}${cur_host}${NC} at ${Yellow}${cur_host_ip}${NC} has been adopted by UniFi controller." | |
else | |
echo -e "${Red}Warning.${NC} Device ${White}${cur_host}${NC} at ${Yellow}${cur_host_ip}${NC} has not been adopted by UniFi controller." | |
echo -e "Checking again in ${wait} seconds. Please wait...\n" | |
sleep ${wait} | |
echo "Checking again..." | |
if [[ "${chk_cmd}" == "${inform}" ]]; then | |
echo -e "${Green}Device${NC} ${White}${cur_host}${NC} at ${Yellow}${cur_host_ip}${NC} has been successfully adopted by UniFi controller." | |
else | |
echo -e "${Red}Failure.${NC} Device ${White}${cur_host}${NC} at ${Yellow}${cur_host_ip}${NC} has not been adopted by UniFi controller. ${Yellow}Please set the inform URL on the device.${NC}" | |
fi | |
fi | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
set-inform
command is an alias on the remote host. Obviously we don't have the same env as a remote ssh login. The same is true for theinfo
command.set-inform='mca-cli-op set-inform'
info='mca-cli-op info'