Automated Unifi AP Reboot Script for Daily Morning Maintenance
Unify your network by implementing an automated script to reboot your Unifi APs at regular intervals. This post will guide you through the process of creating a daily morning maintenance script to ensure your wireless access points are always ready for use.
We all know that sometimes our Unifi APs can be temperamental, and we need to perform a manual reboot to get them working again. However, this wasn’t a constant issue, and I was lucky enough to have only one or two reboots per week at most. But then, I had to deal with some points of access that were malfunctioning more frequently.
To minimize these issues, I decided to create a script in Linux to automate the reboot process for my Unifi APs every morning before our team started working. This way, everything was ready and waiting for us when we arrived at the office.
Here are the requirements for this script:
- You have Unifi APs
- The script is designed for Unifi AP version 3.2.10
- Remote access to the AP console
- A Linux machine
Now that we’ve got our requirements covered, let’s dive into the script itself. Here it is (rebootAP.sh):
#!/usr/bin/expect
spawn ssh admin@[lindex $argv 0]
expect {
-re ".*Are.*.*yes.*no.*" {
send "yes\n"
exp_continue
}
}
expect "admin@[lindex $argv 0]'s password:"
send "[lindex $argv 1]\n"
expect "BZ.v3.2.10# "
send "reboot\n"
# interact
expect eof
exit
Next, we need to make this script executable by running the following command:
chmod +x rebootAP.sh
Now that our script is ready, let’s execute it with the necessary parameters: IP address of the AP and the password. For example:
rebootAP.sh 10.0.0.112 appass123
To ensure this script runs automatically every morning, we’ll use the crontab in Linux. Since we don’t know the exact location of our script, we need to specify the full path to avoid any security issues. In my case, I have three Unifi APs, so I’ll add three separate lines to the crontab:
00 08 * * * /root/itscripts/rebootAP.sh 10.0.0.111 appass123
05 08 * * * /root/itscripts/rebootAP.sh 10.0.0.112 appass123
10 08 * * * /root/itscripts/rebootAP.sh 10.0.0.113 appass123
This script will reboot our three Unifi APs at 8:00 AM every morning, with a 5-minute interval between each restart. This way, if someone tries to access the network while one of the APs is being restarted, they’ll be automatically directed to the next available AP.
By implementing this automated script, we can ensure our Unifi APs are always ready for use and minimize downtime.