I recently faced a problem with our Cisco AP541N-A-K9 Dual Band Access Points. We have 5 in the office and users would complain that they were getting the “Limited Access” error or would not be able to connect at all. The problem would only happen in certain areas of the office with certain users. If the user would go to another area (switching access points), the error would go away and they would be fine. After troubleshooting the issue, I found that the only fix was to reboot the access point that was giving problems and everything would be fine. This wasn’t the perfect solution though because not all users on that access point would be having issues, and rebooting would kick everyone off for a short period of time.
I found that the best thing to do would be to write a script that would reboot all of the access points early in the morning before the users would get to work. That way all of the access points would have a clean slate to start with. Here’s how I did it:
I figured the best way to do this would be through Ubuntu with a cronjob. I spun up a VM with Ubuntu Server 12.0.4 and got started.
All of the access points have SSH enabled so I connected to one and saw the familier Cisco iOS.
Easily enough, all I need to do is run the Reboot command. I also wanted a way to make sure they did indeed reboot, so I will be taking use of the Get System Uptime command as well.
To start, I will be creating two files on each access point: reboot.sh and uptime.sh
Simple, right? Now lets create our script that will actually be doing all of the work. Hop back to your Ubuntu server and run the following commands:
The reason we are installing sshpass is that we can pass the credentials all in one line of code and we wont have to deal with installing ssh keys on each of the access points. The other app we are installing is MailUtilis, which we will configure to send us an email once the script completes.
Once they are done installing, lets create a file called reboot.sh that will house all of our commands.
You can see in the script that I am calling a /password.txt file. This is where your SSH password will be stored and then passed to the access points. All that this script is doing is calling the two files we created earlier on each of the access points and executing those commands. The 240 second sleep in between reboots is to give the access point enough time to come back online and re-register with the other access points. Once all of the reboots happen, it goes out and grabs the system uptime to verify that they rebooted.
We then need to make this file executable so a quick chmod will do the trick:
Now we need to set up this script to email us when it is done executing. We will be creating another script that will call the previous one, and pipe that out to MailUtilis.
We will also need to run chmod on it as well.
Now lets set up the Cronjob:
I figured 5:30am will allow enough time for them all to reboot before anyone would get in the office. If we set everything up we should be receive an email tomorrow morning.
And there it is! Now every morning I can check my email knowing that all of my access points are fresh and ready for a new day.
Hope this helps!