# Running Macros

Although you must write macros on a computer, you can copy them to the system. Issue the macro command from the CLI to execute both local macros and macros stored remotely.

You can display the commands that are generated by the macro file without executing the commands by using the test keyword. We recommend you confirm that the test display matches your expectations before you execute the macro to run the commands.

You can terminate a macro while it is running by pressing Ctrl+c. You can close Telnet and SSH windows while a macro is running, but the macro does not terminate until it completes the current command.

macro

- Use to execute a macro that generates—and can execute—CLI commands. This command is available in all command modes.
- This command invokes a hidden FTP client and takes place in the context of the current virtual router (VR) rather than the default VR. You must configure the FTP server so that any traffic destined for the VR can reach the VR; typically, you configure the FTP server to reach the default address of the system, which will always be able to reach the VR.
- You can specify both a macro filename and a macro contained within that file. For example, the following command looks for the file confatm.mac and runs the macro named atm0verDs3 contained within the file:
  host1(config)#macro confatm.mac atm0verDs3
- You can specify only a macro filename. The command searches in the specified file for a macro named start. The command fails if the start macro does not exist. For example, the following command looks for the file confatm.mac and runs the macro named start contained within the file:
  host1(config)#macro confatm.mac
- You can specify only the macro name, using the name keyword, if the macro file is stored locally in NVS and has the same name as the included macro you want to invoke. For example, the following command looks for the file confatm.mac and runs the macro named confatm contained within the file:
  host1(config)#macro name confatm
- You must specify a macro filename for remotely stored macro files, as in the following example:
  host1(config)#macro pc:/macros.mac atm0verDs3
- You can pass arguments to the macro; if the argument contains a space or other special character, you must enclose the argument within double quotation marks.
- Use the test keyword to specify that the macro generate, but not execute, the commands. You can look at the output to verify that it is what you want. The test mode is verbose and displays comments.
- Use the verbose keyword to echo commands to the display and display comments as the macro executes. By default the command executes in nonverbose mode.
- There is no no version.
- See macro.

Example

A typical macro application is to iteratively generate a series of commands, as shown in the following macro, atm0verDs3:

    <# atmOverDs3 #>
    <# i:=0; while i++ < 3 #>
    controller t3 9/<#i;'\n'#>
    no shut
    clock source internal module
    framing cbitadm
    ds3-scramble
    !
    interface atm 9/<#i;'\n'#>
    atm vc-per-vp 256
    !
    <# endwhile #>
    !
    interface atm 9/1.1
    encap pppoe
    !
    <# i:=1; while i < 100 #>
    interface atm 9/1.1.<#i;'\n'#>
    encap ppp
    no ppp shut
    no ppp keep
    atm pvc <# i #> 1 <# i #> aal5mux ip
    ip addr 10.1.<#i#>.1 255.255.255.0
    !
    <# i++ #>
    <# endwhile #>
    !
    <# endtmpl #>

If you stored this macro remotely in the macro file, pc:/macros.mac, you issue the following commands to execute the macro:

host1>enable host1#conf t host1(config)#macro pc:/macros.mac atm0verDs3

Alternatively, if you stored this macro locally in the macro file atm0verDs3.mac, you issue the following commands to execute the macro:

host1>enable host1#conf t host1(config)#macro verbose atm0verDs3

The following example shows a portion of the output resulting from executing the atm0verDs3 macro from a local file (the starting and ending comments vary for a remote macro):

    host1(config)#!Macro 'atmOverDs3' in the file 'atmOverDs3.mac' starting execution (Id: 103)
    host1(config)#controller t3 9/1
    host1(config)#no shut
    host1(config)#clock source internal module
    host1(config)#framing cbitadm
    host1(config)#ds3-scramble
    host1(config)#interface atm 9/1
    host1(config)#atm vc-per-vp 256
    host1(config)#controller t3 9/2
    host1(config)#no shut
    host1(config)#clock source internal module
    host1(config)#framing cbitadm
    host1(config)#ds3-scramble
    host1(config)#interface atm 9/2
    host1(config)#atm vc-per-vp 256
    host1(config)#controller t3 9/3
    host1(config)#no shut
    host1(config)#clock source internal module
    host1(config)#framing cbitadm
    host1(config)#ds3-scramble
    host1(config)#interface atm 9/3
    host1(config)#atm vc-per-vp 256

    host1(config)#interface atm 9/1.1
    host1(config)#encap pppoe

    host1(config)#interface atm 9/1.1.1
    host1(config)#encap ppp
    host1(config)#no ppp shut
    host1(config)#no ppp keep
    host1(config)#atm pvc 1 1 1 aal5mux ip
    host1(config)#ip addr 10.1.1.1 255.255.255.0

[display omitted]

    host1(config)#interface atm 9/1.1.99
    host1(config)#encap ppp
    host1(config)#no ppp shut
    host1(config)#no ppp keep
    host1(config)#atm pvc 99 1 99 aal5mux ip
    host1(config)#ip addr 10.1.99.1 255.255.255.0
    host1(config)#!Macro 'atmOverDs3' in the file 'atmOverDs3.mac' ending execution (Id: 103)