Sunday, December 21, 2008

How to Schedule commands on Cisco Router ?

Command schedulers allow you to run commands, or a sequence of commands, once or on a recurring calendar. Learn how you can use the Cisco IOS command scheduler to back up your router's running configuration to the startup configuration on a regular basis.

Cisco IOS has a built-in command scheduler called kron. Introduced in Cisco IOS 12.3(1), this command scheduler is similar to the Windows at program and the UNIX cron or at programs.
Command schedulers allow you to run commands, or a sequence of commands, once or on a recurring calendar.

Use the command scheduler

For example, let's say you want to automatically back up your router's running configuration (in RAM) to the startup configuration (in NVRAM) every Monday night at 10 P.M. You might want to make sure that the system is preserving router changes, even if the router losses power--and even if someone forgets to save his or her changes.

The new IOS command scheduler makes this a relatively easy task. Here's how you can use kron to accomplish this.

First, create a kron policy list. Essentially, this policy list serves as your "script," which lists what you want the router to run at a scheduled time. Here's an example:

Router(config)# kron policy-list backup
Router(config-kron-policy)# cli write
Router(config-kron-policy)# exit

Next, create a kron occurrence, in which you tell the router when and how often you want to run this policy list (i.e., group of commands). Here's an example:

Router(config)# kron occurrence backup at 22:00 Mon recurring
Router(config-kron-occurrence)# policy-list backup

This code sets up your backup job to run every Monday night at 10 P.M. (22:00 in military time).

Finally, verify that you've entered everything correctly by using the show command.

Router# show kron schedule
Kron Occurrence Schedule
backup inactive, will run again in 2 days 22:03:46 at 22:00 on Mon
Router# show running-configuration
(truncated)
kron occurrence backup at 22:00 Mon recurring
policy-list backup
!
kron policy-list backup
cli write
(truncated)

You might be wondering why I used the write command instead of the copy running-configuration startup-configuration commands. While the copy run start command is interactive, the write command is not. In other words, write doesn't prompt to verify what you want to do. It's important to remember that the Cisco IOS Command Scheduler doesn't allow any interactive commands.

Know your limitations

Another thing to look out for is that kron has more limitations than its Windows or UNIX counterparts. For example, you can only use privileged-mode commands with kron; it doesn't allow any Global or Interface configuration commands. This is because it executes each command separately.

In addition, it doesn't allow you to edit the list of commands once you've entered them. Therefore, you should test the command sequence before entering it. If a command in the sequence fails, the router will delete that sequence of commands and not run it again.

Some of these limitations may be due to the fact that the command scheduler's primary design appears to be to allow Cisco routers to contact Cisco's CNS server to request an automatic upgrade. While this is a good use for the command scheduler, you can also use it for a number of other handy tasks.

Learn additional uses

You might be wondering if you could use kron to reboot the router. While it's a good idea to use the command scheduler if you want to reboot your router on a regularly scheduled basis, you can perform a one-time delayed reboot using reload at .... with less complexity.

Additional uses for kron include clearing an interface on a daily schedule, clearing the internal log, and showing the routing table at set intervals and sending it to a log.

In some cases, you may want to log the failure or success of your commands. To do so, you can use the debug command. For example, to view all kron debugging, use debug kron all. (You can also use more specific kron debug commands.)

Once you've enabled debugging, send logging output to the router's system buffer or to a syslog server. In that log, you'll find the command output and whether the commands succeeded or failed.

These are just some examples of how you can use the IOS command scheduler. How would you use the command scheduler on your network? Post your ideas and tricks to this article's discussion.

Best Regards,
Deepak Arora

No comments: