Script To Reboot Cisco Wireless Access Points Daily

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

vi reboot.sh
reboot
vi uptime.sh
get system uptime
view raw gistfile1.txt hosted with ❤ by GitHub

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:

apt-get install sshpass
apt-get install mailutilis
view raw gistfile1.txt hosted with ❤ by GitHub

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.

nano reboot.sh
sshpass -f /password.txt ssh cisco@172.20.1.15 reboot.sh
sleep 240
sshpass -f /password.txt ssh cisco@172.20.1.9 reboot.sh
sleep 240
sshpass -f /password.txt ssh cisco@172.20.1.17 reboot.sh
sleep 240
sshpass -f /password.txt ssh cisco@172.20.1.16 reboot.sh
sleep 240
sshpass -f /password.txt ssh cisco@172.20.1.8 reboot.sh
sleep 240
echo
echo
echo 172.20.1.15 3rd Floor Closet
echo
sshpass -f /password.txt ssh cisco@172.20.1.15 uptime.sh
echo
echo
echo
echo 172.20.1.9 1st Floor Datacenter
echo
sshpass -f /password.txt ssh cisco@172.20.1.9 uptime.sh
echo
echo
echo
echo 172.20.1.17 2st Floor Janitor Closet
echo
sshpass -f /password.txt ssh cisco@172.20.1.17 uptime.sh
echo
echo
echo
echo 172.20.1.16 1st Floor Excersie Room
echo
sshpass -f /password.txt ssh cisco@172.20.1.16 uptime.sh
echo
echo
echo
echo 172.20.1.8 2nd Floor File Room
echo
sshpass -f /password.txt ssh cisco@172.20.1.8 uptime.sh
echo
view raw gistfile1.sh hosted with ❤ by GitHub

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:

chmod u+x reboot.sh
view raw gistfile1.sh hosted with ❤ by GitHub

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.

nano mailreboot.sh
./reboot.sh | mail -s "Wireless Uptime" email@address.com
view raw gistfile1.sh hosted with ❤ by GitHub

We will also need to run chmod on it as well.

chmod u+x mailreboot.sh
view raw gistfile1.sh hosted with ❤ by GitHub

Now lets set up the Cronjob:

crontab -u
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
30 5 * * * cd / && ./mailreboot.sh
view raw gistfile1.sh hosted with ❤ by GitHub

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!

 

 

 

8 thoughts on “Script To Reboot Cisco Wireless Access Points Daily

  1. wayne

    somehow i am having hard time injecting the ‘reboot.sh’ and ‘uptime.sh’

    for the reboot, i had to do “<"
    as for the uptime.sh, i just cna't get the script to read the whole string.. it was only able to read 'get'.
    help?

    Reply
  2. wayne

    somehow i am having hard time injecting the ‘reboot.sh’ and ‘uptime.sh’

    for the reboot, i had to do “<"
    as for the uptime.sh, i just cna't get the script to read the whole string.. it was only able to read 'get'.
    help?

    Reply