Cisco Router – Scheduler for CLI Commands

Recently I’ve been in the process of setting up a new customer network and they had some fairly strange requirements, where most of our customers are fairly adverse to any kind of downtime this customer required a weekly reboot of their equipment out of hours, even on the Core networking equipment. It seems they’d been bitten in the past with what I can only assume was a bug triggered by stuff working, and actually having uptime… any way, who are we to judge.

When it comes to the Cisco routers this was actually fairly easy to setup, the first step is to create a kron (similar to a Linux Cron) job, this just defines what you want to do, the when you want to do it is configured later on.

Assume in the below you can basically swap the rebooting part out to any other command you may want to run.

Auto Reload/Reboot

First off we’ll create a kron policy called “reloadrouter”, then within this we simply define that we wish the router to invoke a “cli” command, and finally which command that we wish it to run, in our case that would be “reload”

kron policy-list reloadrouter
 cli reload
!

Now we’ve got a policy defined the router knows what we expect it to do, the next part is to let is know when we would like that to be run, so basically the Cisco way of doing that is to create an occurrence of the policy, with a time that we want it to “occur”

The below will run our reloadrouter policy at 04:00 AM, and reoccur every day.

kron occurrence reloadrouter at 4:00 recurring
 policy-list reloadrouter
!

Some other ideas

As I said above there’s a load of other cool things that you can do with Kron’s, for example here’s some ideas!

Auto Save Config

Forgetting to save the configuration, save an embarrassing reload in the future!

kron policy-list daily-save-config
 cli write
!
kron occurrence daily-save-config at 4:00 recurring
 policy-list daily-save-config
!

Remove debug

People keep leaving debug running on the routers, auto turn it off!

kron policy-list daily-un-debug
 cli undeb all
!
kron occurrence daily-un-debug at 1:00 recurring
 policy-list daily-un-debug
!

TFTP Backup

Want to do a quick backup of the startup configuration to a TFTP server?

kron policy-list config-backup
cli show startup-config | redirect tftp://10.1.1.1/bkup.cfg
!
kron occurrence config-backup at 1:00 recurring
 policy-list config-backup
!

One thing; please don’t forget the command is only as good as your time keeping, so NTP is always wise with this kind of automation 🙂

Technology enthusiastic with many ongoing online projects one of which is this personal blog PingBin.
While also working full time within a data center designing and maintaining the network infrastructure.

Leave a reply:

Your email address will not be published.