Scheduling of Router Commands

Scheduling of Router Commands

Problem

You want to issue a command for the router to execute at regularly scheduled times.

Solution

Use the router's Kron facility to execute commands at regularly scheduled intervals:

Router#configure terminal 
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#kron policy-list OREILLY
Router(config-kron-policy)#cli write memory
Router(config-kron-policy)#exit
Router(config)#kron occurrence DAILYat5 at 17:00 recurring
Router(config-kron-occurrence)#policy-list OREILLY
Router(config-kron-occurrence)#end
Router#

Cisco first introduced the Kron facility in IOS Version 12.3(1).

It is highly recommended that you configure the router with an accurate time source such as NTP or SNTP before configuring the Kron facilities, as it requires an accurate clock to work correctly. See Chapter 14 for more information on NTP and SNTP.


Discussion

The Cisco Kron facility is similar to the Unix Cron facility in that it allows you to schedule commands to be executed at regular intervals. In essence, it allows you to automate certain administrative functions that the router administrator would otherwise have to perform manually. Of course the major advantage is that once configured correctly, the Kron facility issues the commands at the exact time required and without the chance of typos. In addition, it does not require the administrator be present when the commands are run, which is important, especially in organizations with large numbers of routers.

Let's take a closer look at the configuration of the Kron facility. In the example provided, we have configured the Kron facility to automatically save the configuration to NVRAM each day at 17:00 (5:00PM). First, we configured the kron policy-list and named it "OREILLY" and included the single CLI command "write memory." We then configured the kron occurrence named "DAILYat5" and set the launch time to 17:00. The keyword recurring is required to ensure that the Kron occurrence launches each day as opposed to a single instance. Once the Kron occurrence was configured, then we defined which Kron policies where to be invoked. Note that you can launch more than one Kron policy per occurrence, as shown in the next example:

Router#configure terminal 
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#kron occurrence DAILYat5 at 17:00 recurring
Router(config-kron-occurrence)#policy-list OREILLY
Router(config-kron-occurrence)#policy-list TEST
Router(config-kron-occurrence)#end
Router#

In this example, we have configured two Kron policies to launch via the same Kron occurrence. This means that each day at 17:00 the router will launch both policies.

As with the Unix Cron facility, you can schedule Kron occurrences to run every minute of the hour, once a year, or anywhere in between. To schedule a Kron occurrence to launch every hour, use the in keyword in conjunction with the recurring keyword:

Router#configure terminal 
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#kron occurrence Hourly in 60 recurring
Router(config-kron-occurrence)#policy-list TEST
Router(config-kron-occurrence)#end
Router#

The Kron facility will now launch the Kron occurrence "Hourly" every 60 minutes. To launch a Kron facility once a year, use the following configuration:

Router#configure terminal 
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#kron occurrence Yearly at 00:00 Jan 1 recurring
Router(config-kron-occurrence)#policy-list TEST
Router(config-kron-occurrence)#end
Router#

Unfortunately, there are some rather annoying limitations to the Kron facility. First of all, only EXEC level commands can be issued by the Kron facility, meaning that no configuration-based commands can be issued. Second, the Kron facility won't work with interactive-based EXEC commands, meaning commands that prompt you to verify the command. For instance, in the initial example we issued the CLI command write memory instead of copy running-config startup-config because the write command does not prompt to verify the action whereas the copy command does.

Some potentially useful uses for the Kron facility are saving the configuration to NVRAM, disabling all debug commands, clearing a particular interface, issuing a ping command to keep up a tunnel, etc.

You can view the scheduled Kron occurrences by using the show kron schedule command:

Core#show kron schedule
Kron Occurrence Schedule
DAILYat5 inactive, will run again in 0 days 05:40:54 at 17:00 on

Core#

You can see that the router will launch the Kron occurrence "DAILYat5" in 5 hours and 40 minutes.

See Also