Cisco Command Sender (cisco_send_cmds_rcf)

Top  Previous  Next

This program is very similar to the cisco_send_cmds script except it is designed to send a different set of exec-level commands to each Cisco IOS device.  The specific  commands, and the routers these commands are sent to, are defined in a text file that you create.  The commands are sent in sequential order from top to bottom of the file.  This script can also send configuration commands but the actual commands to enter and exit configuration mode must also be included in the list of commands to send. 

 

Note, for global Cisco router configuration changes, where different configuration commands are needed for each router, the cisco_config_cmds_rcf script is the preferred tool as that script has more comprehensive error checking designed for configuration commands only

 

Program Name: cisco_send_cmds_rcf

 

Script Argument

Description

-rcf <filename>

Short for Router and Command File.  File which contains a List of routers or IP Address along with a file name which contains the list of configuration commands to send to each router (REQUIRED)

-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 command looping and variable substitutions are correct or for just double checking the commands that will be sent .  List of commands are

also written to the file $SCRIPT_HOME/<script_name>_sample_cmds.txt".

(OPTIONAL)

-wm

Saves configuration file to NVRAM after sending the commands.  This would only make sense if any of the commands were configuration commands.  This option performs a "write memory" on the router.  (OPTIONAL)

-ual (1 or 2)

User Access Level.  Tells the script what access-level (1st or 2nd) to log into the router before sending the commands.  By default the script will only go into 1st level access.  (OPTIONAL)

-dir <directory>

If specified, tells script to save output for each device into a separate file.  Files will be saved to the directory specified.  If the directory does not exist, the script will create it.  By default output for all devices is only saved to the detailed trace file.  The directory entered can be either an absolute directory or a relative directory.  If running the script from the GUI, a relative directory is relative to the "SCRIPT_HOME" variable. (From the GUI see Options->Settings). (OPTIONAL)

-autodir <date | time>

Automatically create new unique directory to save output for each device into a separate file.  The choices are date or time

 

The date option will create a new directory consisting  of just the date

e.g. 08012010 for Aug 1st 2010. 

 

The time option will append the time to the date:

e.g. 08012010_12h36m15s

 

If used with the -dir option, the new unique directory will be created under the -dir directory.  If the -dir option is not used, then the new unique directory will be created under the SCRIPT_HOME directory.  Note, if the date option is used and that directory name happens to all ready exist, then files in that directory will be overwritten. There are no safety prompts for the user when using this option.

-urfn

Use Route File Name.  When saving the output data to a separate file for each device, the filename used will be the name/IP Address stated in the -rf file.  The default filename is the router hostname configured on the router.  This option only applies when used with the -dir option. (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)

-nokey

Don't prompt user for encryption key when using encrypted password file.  (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)

 

 

Below shows and example of an rcf file.  This is not a TCL formatted file, it is just a text file.  Lines that begin with a # are comments.  The format of the file is rtrname:filename.  Where rtrname is a DNS name or IP Address and filename is a file that contains the list of commands to send to that specific router.  One entry per line.  The format for the file that contains the specific commands for a particular router is identical to the cisco_send_cmds script. 

 

# Sample template file for cisco_send_cmds_rcf script
# Lines that begind with a # are comments
# Format of file is router:filename
# Where file name contains a list of commands
# that will only be sent to that router
 
nyrtr1:nyrtr1.cmds
10.1.1.2:cmd_file2.cmds

Figure 2 Sample rcf file

 

Identical to the cisco_send_cmds script, the following commands can be entered in the command file and the router will automatically answer any additional confirmations or prompts.  (Note, these commands are not entered in the -rcf file)

 

Notes:

(These commands are not entered in the -rcf file)

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

 

Command

Description

clear counters

clear counter

The Cisco IOS clear counters command requires confirmation after entering the command in the CLI.  The script will automatically send the confirmation to clear the counters.

clear logging

clear log

The Cisco IOS clear logging (or clear log) command requires confirmation after entering the command in the CLI.  The script will automatically send the confirmation to clear the log.

clear line <line number>

The Cisco IOS clear line <line number> command requires confirmation after entering the command in the CLI.  The script will automatically send the confirmation to clear the line.

clear ip traffic

The Cisco IOS clear ip traffic command requires confirmation after entering the command in the CLI.  The script will automatically send the confirmation to clear the ip traffic counters.

reload

reload /noverify

The Cisco IOS reload command requires confirmation after entering the command in the CLI.  The script will automatically send the confirmation to reload the router.  Note, if after entering the reload command, the router could respond with a message stating "the configuration has change, do you wish to save the configuration file before rebooting?" If this happens, the router will NOT reload the router, it will log an error message and exit from the router.

 

The reload /noverify option is supported and needed in the case when the "file verify auto" command is present in the IOS configuration.  When the file verify auto command is configured, the router verifies the integrity of the IOS file before reloading the router.  If the "file verify auto" option is present and the the /noverify option is not used, the Automater script will fail when trying to reload the router.

 

Note, do not use the reload command in the input file and the -wm option on the command line together. If you wish to perform a write mem before issuing a reload, then add the "wr mem" to the input command file before the reload command.  (This is because the -wm is performed after all of the commands in the input file are issued but the reload command will terminate the telnet session and the write mem can no longer be performed)

write mem

wr mem

If the script sees this string as one of the commands to send, internally it will run a separate procedure that is looking for the string [OK].  If it doesn't see this, it will log an error.  Note, you could also just use the -wm command line option if you want to save the configuration after all of the commands are sent.

configure replace

config replace

The Cisco IOS configure replace command requires confirmation after entering the command in the CLI.  The script will automatically send the confirmation.  In addition, it will also look for the string Rollback Done.  If if doesn't see this, it will log an error.

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.

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.

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

 

The following is a sample command file which performs a show ip ospf neighbors, show interface, then pauses for 15 seconds because the user wishes to visually examine the output of the show interface command (in real time).  Then it clears the counters.

 

show ip ospf neighbors
show interface
SLEEP 15
clear counters

 

There is also an option for setting the User Access Level.  By default the script will only log into first level access on the router.  If you are sending commands that require second level access, then use the -ual option and set it to 2 (e.g. -ual 2).

 

If configuration commands are also included in the list of commands and you wish those changes to be saved to NVRAM, then the -wm option must be used.  By default, the configuration commands will not be saved to NVRAM. 

 

This program also has the option to be run in Safe and SuperSafe mode which should be considered when running scripts in production environments.

 

Sample Command: The following script run will telnet to each router listed in the bgp_show.rcf file and send only the commands associated with that router.  The script will go into enable mode before issuing the commands because of the -ual 2 option.  If there are any errors while issuing any of the commands, the script will immediately terminate because of the -ssafe option (SuperSafe Mode).  The script will not prompt the user for passwords because the passwords are being read in from the logins.txt file (-pw option).

 

cisco_send_cmds_rcf -pw logins.txt -rcf bgp_show.rcf -ssafe -ual 2