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:
- Define the policy with the commands that will be executed:
- enable
- configure terminal
- kron policy-list list-name
- cli command
- -Repeat Step 4 for all EXEC CLI to run at the same time or interval-
- exit
- Define the policy occurrences:
- enable
- configure terminal
- kron occurrence occurrence-name [user user-name] {in [[numdays:]numhours:]nummin | at hours:min [[month] day-of-month] [day-of-week]} {oneshot | recurring}
- policy-list list-name
- -Repeat Step 4 for all policies to run at the same time or interval-
- 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:
Hi there, how do I Kron via https / scp to a windows 2012 IIS box? (tftp & ftp are no secure enough options). Thanks in advance.