Global Router Configuration Tool  (cisco_config_cmds)

Top  Previous  Next

This program will send any number of configuration commands to a single IOS device or a list of IOS devices.  The commands that are sent are defined in a text file (any name), that you create, or specified directly on the command line using the -cmd option.  This file MUST NOT include the commands needed to enter and exit configuration mode on the IOS device.  The script will automatically enter those commands.  The commands are sent in sequential order from top to bottom of the file or the order in which they are defined if using the -cmd options.

 

 

Program Name: cisco_config_cmds

 

Script Argument

Description

-rf <filename>

List of routers or IP Address/(DNS hostname) to run script against (REQUIRED -rf or -ipaddr)

 

NOTE: Cannot use the -ipaddr and the -rf option at the same time!

-ipaddr <ip_address or routername>

IP address or router/switch name (if defined in hosts file or DNS)

Use -ipaddr to send commands to a single device or -rf to send commands to list of devices specfied in file.  (REQUIRED -rf or -ipaddr)

 

NOTE: Cannot use the -ipaddr and the -rf option at the same time!

-cf <filename>

File which contains a list of configuration commands to send to router.  These MUST BE configuration commands only!!! (Do not include commands to enter and exit configuration mode)  One configuration command per line.  Lines that begin with a "#" are considered comments and will not be sent to the router.

(REQUIRED -cf or -cmd)

 

NOTE: Cannot use the -cf and the -cmd option at the same time!

-cmd <command>

Command to send to router.  Useful when only needing to send a few commands to a single device or list of devices.  It saves you the time of having to create a text file with only a few commands in it.  If the command contains spaces then it must be enclosed in double quotes (only when running script from cli, not GUI. This option can be used up to 7 times when used with the GUI.  The command line version of this script can repeat this option an unlimited number of  times.  However, for more than 5 to 7 commands, it is recommended to put the commands in a text file and use the -cf option. (REQUIRED -cf or -cmd)

 

NOTE: Cannot use the -cf and the -cmd option at the same time!

 

Example:

-cmd "ip host test 1.1.1.1"

-testmode

Test Mode. Build and display the commands that would have been sent to the devices but DO NOT actually connect to the devices and send the commands.  Useful for confirming your variable substitutions are correct.  List of commands are

also written to the file $SCRIPT_HOME/cisco_config_cmds_sample_cmds.txt".

(OPTIONAL)

-wm

Saves configuration file to NVRAM after making the configuration changes.  This option performs a "write mememory" on the router.  (OPTIONAL)

-safe

Safe Mode.  If an error occurs while sending a configuration command to a router in the list, all subsequent commands to that router will not be sent.  The script will continue on to the next router on the list and continue sending commands.  (OPTIONAL)

-ssafe

SuperSafe Mode.  Abort Script if there is an error while sending any of the configuration commands to any of the routers. (OPTIONAL)

-ssh

Use Secure Shell when accessing routers.  Do NOT use with -pw option. (OPTIONAL)

-pw <filename>

Login/Password File.  (OPTIONAL)

-log <filename>

Save detailed trace file to a name other than the default file name.  (OPTIONAL)

-ulog

Unique Log file.  Save detailed trace log file to a Unique filename automatically created by script. Filename will be in format of scriptname_timestamp.log. (OPTIONAL)

 

The configuration command file (-cf <filename>) should contain a list of configuration commands that will be sent to each router.  This is a plain text file that must contain one command per line.  Lines that begin with a "#" are considered comments and will not be sent to the router as a command.  Th SLEEP command is a special command that will NOT actually be sent to the router. If desired, this is a method to introduce a delay between configuration commands.  The syntax is the SLEEP <seconds>  (all capitals).  Seconds can be a whole integer (e.g. 2) or a real number (e.g. 1.5).  The SLEEP command MUST be entered in all CAPITAL letters otherwise it will be interpreted as a command to send to the router.  Note, this is not typically needed but may be useful if you would like to watch the script as it is running to visually inspect the output of a particular command.

 

This script also has the option to run in Test Mode using the -testmode option defined above.  With this option, the exact commands that would have been sent to the routers are written to a file (stored in the SCRIPT_HOME directory).  The script does not actually login to any devices or send any commands.  It is recommended this feature be used when using LOOPING and COUNTER variables (see below)

 

By default, the configuration commands will not be saved to NVRAM.  Use the -wm option to save the configuration changes.

 

This program also has the option to be run in Safe and SuperSafe mode which should be considered when running scripts in production environments.  If entering a configuration command results in an error on the router and the script is running in Safe or SuperSafe mode, the config will not be saved to NVRAM even if the -wm option is applied.  If the script is NOT running in Safe or SuperSafe mode, and the -wm option is applied, the config WILL be saved to NVRAM even if there are one or more commands that caused configuration errors.

 

The following special commands are supported by this script.

(Note, output of the commands listed below will NOT be displayed in the contents of individual output files when using the -dir option)

 

Command

Description

SLEEP <seconds>

The SLEEP command is not a command that will be sent to the router.  If desired, this is a method to introduce a delay between commands.  Seconds can be a whole integer (e.g. 2) or a real number (e.g. 1.5).  The SLEEP command must be entered in all CAPITAL letters otherwise it will be interpreted as a command to send to the router.  It must also start at the beginning of the line (no leading spaces or tabs).  Note, this is not typically needed but may be useful if you would like to watch the script as it is running to visually inspect the output of a particular command. CASE SENSITIVE

LOOPSTART <num>

or

LOOPEND

Allows the capability to send the same command(s) over and over, a specified number of times.  The command(s) that will repeated are the commands between the LOOPSTART and LOOPEND commands.  See Command Looping for more information.  CASE SENSITIVE

COUNTERVAR <variable> <start_num> <increment by>

Define a counter variable. Provides a method to define a variable in the command file; it must be used with the LOOPING feature.  The variable must be a single alphabetical character.  "start_num" is the number that the counter will start at.  It will increment by the <increment by> number each time through the LOOP.  See Counter Variables for more information. CASE SENSITIVE

 

Sample Command 1: The following command will send the configuration commands listed in file snmp_cmds.cmds to the routers listed in the file rtrs.rt. After the configuration commands are entered, the config will be saved to NVRAM because of the -wm option.  If there are any errors while sending a particular configuration command, the script will abort all remaining commands to that router and continue on to the next router because of the -safe option (SAFE Mode).  The detailed trace-log will be saved to the file snmp_log instead of the default file name of cisco_config_cmds.log (notice this argument was listed first on the command line).  The script will not prompt the user for passwords because the passwords are being read in from the logins.txt file (-pw option).

 

cisco_config_cmds -log snmp_log -pw logins.txt -rf rtrs.rt -cf snmp_cmds.cmds -wm -safe

 

Sample Command 2: The following script will shutdown interface Gi 0/18 on switch 192.168.0.10.   The output log will be saved to an automatically generated unique filename because of the -ulog option.  The script will not prompt the user for passwords because the passwords are being read in from the logins.txt file (-pw option).  At the first occurrence of an error, the script will abort because of the -safe option.  If there are no errors, the config will be saved to NVRAM because of the -wm option.

 

cisco_config_cmds -ulog -pw logins.txt -ipaddr 192.168.0.10 -cmd "int Gi 0/18" -cmd "shutdown" -wm -safe