.NODE

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

Chapter 14.

Router Configuration and File Management

Router Management

User Access and Privilege Levels

TACACS+

IP Routing

RIP

EIGRP

OSPF

BGP

Frame Relay

Handling Queuing and Congestion

Tunnels and VPNs

Dial Backup

NTP and Time

DLSw

Router Interfaces and Media

Simple Network Management Protocol

Logging

Access-Lists

DHCP

NAT

First Hop Redundancy Protocols

IP Multicast

IP Mobility

IPv6

MPLS

Security

Appendix 1. External Software Packages

Appendix 2. IP Precedence, TOS, and DSCP Classifications

Index

show all menu





Cisco IOS Cookbook
Cisco IOS Cookbook (Cookbooks (OReilly))
ISBN: 0596527225
EAN: 2147483647
Year: 2004
Pages: 505
Similar book on Amazon

Flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net