macro name
Use the macro name Global Configuration mode command to define a macro. There are two types of macros that can be defined:
-
Global macros define a group of CLI commands that can be run at any time.
Smartport macros are associated with Smartport types. For each Smartport macro there must be an anti macro (a macro whose name is concatenated with no_). The anti macro reverses the action of the macro.
If a macro with this name already exists, it overrides the previously-defined one.
Use the no form of this command to delete the macro definition.
Syntax
macro name macro-name
no macro name [macro-name]
Parameters
-
macro-name—Name of the macro. Macro names are case sensitive.
Command Mode
Global Configuration mode
User Guidelines
A macro is a script that contains CLI commands and is assigned a name by the user. It can contain up to 3000 characters and 200 lines.
Keywords
Macros may contain keywords (parameters). The following describes these keywords:
-
A macro can contain up to three keywords.
-
All matching occurrences of the keyword are replaced by the corresponding value specified in the macro command.
-
Keyword matching is case-sensitive
Applying a macro with keywords does not change the state of the original macro definition.
User Feedback
The behavior of a macro command requiring user feedback is the same as if the command is entered from terminal: it sends its prompt to the terminal and accepts the user reply.
Creating a Macro
Use the following guidelines to create a macro:
-
Use macro name to create the macro with the specified name.
-
Enter one macro command per line.
-
Use the @ character to end the macro.
-
Use the # character at the beginning of a line to enter a comment in the macro.
In addition, # is used to identify certain preprocessor commands that can only be used within a macro. There are two possible preprocessor commands:
#macro key description - Each macro can be configured with up to 3 keyword/description pairs. The keywords and descriptions are displayed in the GUI pages when the macro is displayed.
The syntax for this preprocessor command is as follows:
#macro key description $keyword1 description1 $keyword2 description2 $keyword3 description3
A keyword must be prefixed with '$'.
#macro keywords - This instruction enables the device to display the keywords as part of the CLI help. It accepts up to 3 keywords. The command creates a CLI help string with the keywords for the macro. The help string will be displayed if help on the macro is requested from the macro and macro global commands. The GUI also uses the keywords specified in the command as the parameter names for the macro. See Example 2 and 3 below for a description of how this command is used in the CLI.
The syntax for this preprocessor command is as follows:
#macro keywords $keyword1 $keyword2 $keyword3
where $keywordn is the name of the keyword.
Editing a Macro
Macros cannot be edited. Modify a macro by creating a new macro with the same name as the existing macro. The newer macro overwrites the existing macro.
The exceptions to this are the built-in macros and corresponding anti-macros for the Smartport feature. You cannot override a Smartport macro.
Scope of Macro
It is important to consider the scope of any user-defined macro. Because of the potential hazards of applying unintended configurations, do not change configuration modes within the macro by using commands such as exit, end, or interface interface-id. With a few exceptions, there are other ways of executing macros in the various configuration modes. Macros may be executed in Privileged Exec mode, Global Configuration mode, and Interface Configuration mode (when the interface is NOT a VLAN.)
Examples
Example 1 -The following example shows how to create a macro that configures the duplex mode of a port.
switchxxxxxx(config)# macro name dup
Enter macro commands one per line. End with the character ‘@’.
#macro description dup
duplex full
negotiation
@
Example 2 -The following example shows how to create a macro with the parameters: DUPLEX and SPEED. When the macro is run, the values of DUPLEX and SPEED must be provided by the user. The #macro keywords command enables the user to receive help for the macro as shown in Example 3.
switchxxxxxx(config)# macro name duplex
Enter macro commands one per line. End with the character ‘@’.
duplex $DUPLEX
no negotiation
speed $SPEED
#macro keywords $DUPLEX $SPEED
@
Example 3 -The following example shows how to display the keywords using the help character ? (as defined by the #macro keywords command above) and then run the macro on the port. The #macro keywords command entered in the macro definition enables the user to receive help for the macro, as shown after the words e.g. below.
switchxxxxxx(config)# interface gi1/0/1
switchxxxxxx(config-if)# macro apply duplex ?
WORD <1-32> Keyword to replace with value e.g. $DUPLEX, $SPEED
<cr>
switchxxxxxx(config-if)# macro apply duplex $DUPLEX ?
WORD<1-32> First parameter value
<cr>
switchxxxxxx(config-if)# macro apply duplex $DUPLEX full $SPEED ?
WORD<1-32> Second parameter value
switchxxxxxx(config-if)# macro apply duplex $DUPLEX full $SPEED 100