[Contents] [Prev] [Next] [Index] [Report an Error]

Scheduling Macros

You can schedule a macro to run once at a specific time, after a periodic interval, or at a periodic time of day, day of the week, or day of the month. You can schedule macros for automatic configurations and use it for troubleshooting.

A single macro file can contain many macro definitions. You can schedule every definition individually. Scheduled macros must be local files and cannot be deleted from the file system. A directory report lists scheduled macros. The maximum number of scheduled macros is 100. In Global Configuration mode, the setting persists on reboot, but in Privileged Exec mode, it does not persist on reboot.

After unified ISSU is started, scheduled macros dol not run. Macro scheduling supports high availability (HA) using mirrored storage. Macros scheduled to run persist during an SRP switchover operation, whether scheduled in Privilege Exec or Global Configuration mode.

To schedule macros to run at a specified time or interval:

  1. To schedule a macro to run every 30 minutes:
    host1(config)#schedule macro interval frequency 30 abc.mac getuptime
  2. Issue the show macro command to verify the scheduled time.
    host1#show schedule macro abc.mac
    abc.mac getuptime scheduled to run at 2007-02-14 11:58:06

Example

Scheduling macro commands.

host1#schedule macro interval frequency 30 john.mac getuptime
host1#schedule macro interval time-of-day 00:10 day-of-month 2 fred.mac freddie
host1#configure terminal
host1(config)#schedule macro joe.mac interval time-of-day 00:00 day-of-week sunday start
host1(config)#exit
host1#schedule macro at 20:00 February 14 john.mac getuptime
host1#schedule macro at 20:00 February 16 larry.mac getuptime

To show the set of currently scheduled macros (asterisks indicate persistent macros):

host1#show schedule macro
interval                                 
  macro                 privilege        interval        frequency                                
file name     macro       level        time-of-day       (minutes)        schedule         started
---------   ---------   ---------   ------------------   ---------   -------------------   -------
fred.mac    Freddie        15       00:10 DayOfMonth:2      ---      2007-03-02 00:10:00     ---  
*joe.mac     start         15       00:00 sunday            ---      2007-02-18 00:00:00     ---  
john.mac    getuptime      15              ---              30       2007-02-14 14:26:38     ---  
larry.mac   start          15              ---              ---      2007-02-16 20:00:00     ---  
moe.mac     start          15              ---              ---      2007-02-14 20:00:00     --- 

To display the run time of one macro scheduled in Global Configuration mode, creating an entry that l persists across reboots:

host1#show schedule macro joe.mac
joe.mac start is persistent and scheduled to run at 2007-02-18 00:00:00

To display the start time of one running macro:

host1#show schedule macro john.mac
john.mac getuptime started at 2007-02-14 14:26:39

When you show the running configuration, joe.mac is the only one reported, because the other macros were scheduled in Privileged Exec mode.

host1#show conf | include schedule
schedule macro joe.mac interval time-of-day 00:00 day-of-week sunday start

When you display the directory listing, it shows the scheduled macros are all in-use and cannot be deleted:

										         unshared	   							  in 
            file                  size 		  size         date (UTC)        use
-----------------------------   --------   --------   -------------------   ---
disk0:m.mac                          438        438   01/26/2007 10:12:26    ! 
disk0:fc.mac                         515        515   01/26/2007 12:29:14    ! 
disk0:b.mac                         7728       7728   02/05/2007 13:55:10    ! 
disk0:c.mac                          146        146   02/07/2007 16:09:12    ! 
disk0:mmcX2.rel                 83859484   83859484   02/05/2007 16:01:50    ! 										
host1#delete joe.mac
% File in use

Example

Running a scheduled macro one time. Run macro m in m.mac at 14:35 today.

host# more m.mac
<# m(left,right,third) #>
<# mult := left * right #>
<# multFinal :=  mult * third #>
<# env.setResult("operation", "" $ left $ " * " $ right $ " * " $ third) #>
<# env.setResult("theResult", "" $ multFinal) #>
<#endtmpl#>
host1#schedule macro at 14:35 m.mac m

host1#show schedule macro m.mac

                                              interval
  macro             privilege    interval     frequency
file name  macro     level     time-of-day   (minutes)      schedule        started
---------  -------- ---------  ------------  --------- -------------------  ------- 
m.mac      Freddie      15     00:10 sunday     ---    2008-09-28 00:00:00    ---
host1#

When you show the directory listing, the schedule macro m.mac is marked in use and cannot be modified.

                                           unshared                         in 
            file                  size       size         date (UTC)        use
-----------------------------   --------   --------   -------------------   ---
disk0:m.mac                          438        438   01/26/2007 10:12:26    ! 
disk0:fc.mac                         515        515   01/26/2007 12:29:14      
disk0:b.mac                         7728       7728   02/05/2007 13:55:10    ! 
disk0:c.mac                          146        146   02/07/2007 16:09:12      
disk0:mmcX2.rel                 83859484   83859484   02/05/2007 16:01:50    ! 

Observe the macroScheduler log for the execution of macro m.mac:

NOTICE 02/14/2007 14:35:01 macroScheduler: macro m.mac started with ID 3
NOTICE 02/14/2007 14:35:01 macroScheduler: macro m.mac with ID 3 ran
successfully
NOTICE 02/14/2007 14:35:01 macroScheduler: (Id: 3) operation is 7 * 6 * 5
NOTICE 02/14/2007 14:35:01 macroScheduler: (Id: 3) theResult is 210

After the macro is executed, it is no longer in the list of scheduled macros.

host1#show schedule macro m.mac
% Command failed
                                           unshared                         in 
            file                  size       size         date (UTC)        use
-----------------------------   --------   --------   -------------------   ---
disk0:m.mac                          438        438   01/26/2007 10:12:26     
disk0:fc.mac                         515        515   01/26/2007 12:29:14      
disk0:b.mac                         7728       7728   02/05/2007 13:55:10    ! 
disk0:c.mac                          146        146   02/07/2007 16:09:12      
disk0:mmcX2.rel                 83859484   83859484   02/05/2007 16:01:50    ! 

Example

Macro getuptime, scheduled to run at a regular interval uses regular expression matching to find the system running time in the show versionreport. It then uses regular expression matching on the line containing the system running time to determine the days, hours, minutes, and seconds.

host1#schedule macro interval frequency 60 b.mac getuptime
host1#show schedule macro

b.mac getuptime scheduled to run at 2007-02-14 11:58:06

See the macroScheduler log for the execution of macro b.mac.

NOTICE 02/14/2007 11:26:20 macroScheduler: macro b.mac started with ID 3
NOTICE 02/14/2007 11:26:21 macroScheduler: macro b.mac with ID 3 ran
successfully
NOTICE 02/14/2007 11:26:21 macroScheduler: (Id: 3) Days: is 0 days
NOTICE 02/14/2007 11:26:21 macroScheduler: (Id: 3) Hours: is 0 hours
NOTICE 02/14/2007 11:26:21 macroScheduler: (Id: 3) Minutes: is 17 minutes
NOTICE 02/14/2007 11:26:21 macroScheduler: (Id: 3) Seconds: is 16 seconds

After the macro is run, display the next scheduled run time:

host1#show schedule macro b.mac

b.mac at 2007-02-14 12:59:09 host1#

The file b.mac continues to be in use and cannot be deleted.

                                           unshared                         in 
            file                  size       size         date (UTC)        use
-----------------------------   --------   --------   -------------------   ---
disk0:m.mac                          438        438   01/26/2007 10:12:26     
disk0:fc.mac                         515        515   01/26/2007 12:29:14      
disk0:b.mac                         7728       7728   02/05/2007 13:55:10    ! 
disk0:c.mac                          146        146   02/07/2007 16:09:12      
disk0:mmcX2.rel                 83859484   83859484   02/05/2007 16:01:50    ! 
host1#delete b.mac
% File in use

The macro macro b.mac runs every 60 minutes.

NOTICE 02/14/2007 14:47:47 macroScheduler: macro b.mac started with ID 5
NOTICE 02/14/2007 14:47:49 macroScheduler: macro b.mac with ID 5 ran
successfully
NOTICE 02/14/2007 14:47:49 macroScheduler: (Id: 5) Days: is 0 days
NOTICE 02/14/2007 14:47:49 macroScheduler: (Id: 5) Hours: is 1 hour
NOTICE 02/14/2007 14:47:49 macroScheduler: (Id: 5) Minutes: is 25 minutes
NOTICE 02/14/2007 14:47:49 macroScheduler: (Id: 5) Seconds: is 33 seconds
host1#show schedule macro
b.mac getuptime scheduled to run at 2007-02-14 14:52:47

Related Topics


[Contents] [Prev] [Next] [Index] [Report an Error]