Counter Variables

Top  Previous  Next

New with version 4.5 is the ability to include commands, which are variables, that increment while inside a command loop (i.e., LOOPSTART/LOOPEND).  This is accomplished through the use of the keyword COUNTERVAR (all capitals) in the command file.  Multiple counter variables can be defined in one command file.  When the variable is referenced inside the command LOOP, it must be preceded with a $.  The amount the variable will increment by, each time through the loop, is defined by the increment_by parameter.  The exact format is:

 

COUNTERVAR <variable> <start_integer> <increment_by>

 

variable - must be a single alphabet character

start_integer - start count

increment_by - amount incremented each time through the loop

 

The scripts that support this feature are:

 

cisco_send_cmds

cisco_send_cmds_rcf

cisco_config_cmds

cisco_config_cmds_rcf

pix_send_cmds

catos_send_cmds

generic_send_cmds

nxos_send_cmds

nxos_config_cmds

 

When used with the cisco_config_cmds script, the command file below will create 150 sub-interfaces along with some interface sub-commands.  There are 2 counter variables defined: X and Y.  X will start at the number 500 and Y will start at the number 1.  Each time through, the loop each counter will increment by 1.  Wherever $X and $Y are referenced inside the command loop, the current value of that variable will substituted.

 

 

After the sub-interfaces are created, the script will perform a "do show run".  Note, the key word "do" is needed because this example command file was written to be used by the cisco_config_cmds script.

 

 

COUNTERVAR X 500 1
COUNTERVAR Y 1 1
 
LOOPSTART 150
 
interface FastEthernet 0/5/0.$X
encapsulation dot1Q $X
ip address 10.10.$Y.1 255.255.255.0
 
LOOPEND
 
do show run

 

 

       Note:  Nested Loops are not supported.

 

 

Note, if running the Linux command line version of any of the scripts below AND using the -cmd option with the COUNTERVAR feature, any occurrences of $ must be preceded with a backslash "\".  This is because Linux shell substitution will occur on the command line if the backslash is omitted.  This does not apply when running the scripts from the GUI or from the Microsoft Windows cmd shell.

 

cisco_config_cmds

cisco_send_cmds

nxos_config_cmds

nxos_send_cmds

pix_send_cmds

generic_send_cmds

 

 

Example:

cisco_config_cmds -ip 10.1.1.1 -cmd "COUNTERVAR A 100 1" -cmd "LOOPSTART 10" -cmd "vlan \$A" -cmd LOOPEND