Scripting

Scripting Unifi AP daily reboot with Expect

Written by Marc-Andre

Here’s how to script the reboot of your Unifi access points to minimize the impact of their random crashes. Ubiquiti UniFi APs are really handy access points. But you get what you pay for (they tend to randomly crash and stop forwarding traffic for no reason). The only solution so far has been a reboot of the AP.

This script is a simple loop that ssh into each AP. Then it uses Expect to send the “reboot” command.

All you need to edit is the variables login, password and ap. You can add as many ap[x] as you need. The For Loop will automatically go through all of them.

About the expert

Marc-Andre

I'm currently certified as a Cisco Certified Network Professional (CCNP) with a background as a system administrator. If you're in Montreal, send me an email. I'll be happy be to chat with you in person. Else, you can always find me in the forum.

3 Comments

  • Hello,

    Thanks for sharing the script but did i have to launch it from the controller ? my controller is on a windows server and how can I execute it ? from wchich tool or program ?

    Thanks

    • You can install expect on Windows to run this script, but it is a lot easier to install expect on Linux.
      Here’s what you need to do:
      1. Install CentOS on a virtual machine in the same network.
      2. Install expect by running this command: #yum install expect expectk
      3. Copy paste the script into a file.
      4. Enable the execution of the file with the command: #chmod + x the_script_file
      5. Create a cron job to run this script every night.

Leave a Comment