Nov
22
2010

Cron? no Kron :)

Cron is a time-based job scheduler in Unix-like computer operating systems. The name cron comes from the word “chronos”, Greek for “time”. Cron enables users to schedule jobs (commands or shell scripts) to run periodically at certain times or dates. It is commonly used to automate system maintenance or administration, though its general-purpose nature means that it can be used for other purposes, such as connecting to the Internet and downloading email.

What can I use to schedule a script or a command in Cisco? The kron feature :)

Kron provides the ability to schedule some EXEC command-line interface (CLI) commands to run at specific times or at specified intervals.

Use Kron feature is very simple and it is based on two steps:

  1. Define the policy with the commands that will be executed:
    1. enable
    2. configure terminal
    3. kron policy-list list-name
    4. cli command
    5. -Repeat Step 4 for all EXEC CLI to run at the same time or interval-
    6. exit
  2. Define the policy occurrences:
    1. enable
    2. configure terminal
    3. kron occurrence occurrence-name [user user-name] {in [[numdays:]numhours:]nummin | at hours:min [[month] day-of-month] [day-of-week]} {oneshot | recurring}
    4. policy-list list-name
    5. -Repeat Step 4 for all policies to run at the same time or interval-
    6. end

 

Example #1:
In this example, I save the running-configuration to the startup-configuration each 4 hours:

Ciscozine(config)#kron policy-list save
Ciscozine(config-kron-policy)#cli write
Ciscozine(config-kron-policy)#exit
Ciscozine(config)#
Ciscozine(config)#kron occurrence four-hours in 04:00
Ciscozine(config-kron-occurrence)#policy-list save
Ciscozine(config-kron-occurrence)#exit
Ciscozine(config)#
Ciscozine#sh kron schedule
Kron Occurrence Schedule
four-hours inactive, will run again in 0 days 03:59:40

Ciscozine#

Example #2:
In this example, I disable the debug command at midnight (0:00):

Ciscozine(config)#kron policy-list nodebug
Ciscozine(config-kron-policy)#cli undeb all
Ciscozine(config-kron-policy)#exit
Ciscozine(config)#
Ciscozine(config)#kron occurrence midnight at 00:00
Ciscozine(config-kron-occurrence)#policy-list nodebug
Ciscozine(config-kron-occurrence)#exit
Ciscozine#show kron schedule
Kron Occurrence Schedule
midnight inactive, will run again in 0 days 06:02:49 at 0 :00 on
Ciscozine#

Below the video with the two examples:

 

References:

Summary
Cron? no Kron :)
Article Name
Cron? no Kron :)
Description
Kron provides the ability to schedule some EXEC command-line interface (CLI) commands to run at specific times or at specified intervals.
Author