Generic Command Sender (generic_send_cmds)

Top  Previous  Next

The generic command sender script was added to the suite of scripts to “handle” Non Cisco devices.  The purpose of this script is to send a list of commands to any Non-Cisco device.  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.  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.  The primary feature of this script is the ability to login to many different types of CLI based devices.  You, the user, define the login sequence and prompts with variables.

 

With the introduction of this script, two new device types for the login/password file were created; G1 and G2.  G1 device types are devices that only prompt the user for a password when logging in.  G2 device types are devices that prompt the user for a username and then a password when logging in.  An example of a G1 type login is a Cisco router (when TACACS and Usernames are NOT configured).  Here, you are just prompted for a password and then you are in the router.  An example of a G2 type login is a Linux based system.  Here, you are prompted for a Login Name and a Password. 

 

If you are not using the login/password file, the G1/G2 convention does not apply; the script will prompt you for the information needed.  

 

Program Name: generic_send_cmds

 

Script Argument

Description

-rf <filename>

List of 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 devicename>

IP address or 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 commands to send to devices.  One 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 device(s).  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 "show version"

-sf <filename>

This is the input file that defines the device prompts and other information about the “generic” device.  (REQUIRED)

-ual (1 or 2)

User Access Level.  Tells the script what access-level (1st or 2nd) to log into the device before sending the commands.  For example, if you were sending commands to a UNIX system and the commands needed to be sent by “root”, but you could not login remotely with the root username, then you would use a value of 2.  The script would log you in with another Username and password and then su to root because of the “ual 2” option. 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.

-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

Dont 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)

 

The command file (-cf <filename>) should contain a list of commands that will be sent to each router.  This is not a TCL file, it 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.

 

The following commands can also be entered in the command file:

 

Command

Description



SLEEP <seconds>

The SLEEP command is not a command that will be sent to the switch.  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 switch.  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.

 

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).

 

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

 

The device prompt definitions and other variables are defined in the input file (-sf <filename>).  A sample input file is (generic_send_cmds_template.txt).  If the end-user installation instructions were followed (Section3.2.2), this sample template file should be in the same directory where you run the scripts from.  (Note, for MS Windows, the installation utility automatically copies this template file to the C:\Program Files\net-sense\userdata directory.)

 

The table below describes the variables in that file.  The sequence, in which the variables are defined in the template file, should correspond to the actual order for when they are needed; when logging into a device.  Although, the order of these variables is NOT significant, it probably helps to keep them in the order outlined in the template file.

 

Variable

Description

LOGIN_PROMPT

This is the prompt that the user sees when trying to login to a device and a Username/Login_name is required.  Some examples include "Username:" or "Login:" (case sensitive).  Note, this variable is not reference if a Username/Login_name is not used.

PASSWORD_PROMPT

The prompt that asks you for a first level password (case sensitive).

1ST_LEVEL_PROMPT

First level prompt character(s).  This is the character(s) usually following the device name when in 1st level access mode.  An example of a Cisco router is

NY-router1>

So the value of 1ST_LEVEL_PROMPT would be ">".  If there is a "space" after this character, the space must be included!

E.g. "> ".

TERM_LENGTH_ZERO_CMD

This is the command that will allow the device to send data to the user terminal without prompting the user to enter "return" or "space-bar" if more than one screen full of data is sent to the user terminal. For Cisco devices, the the command is "terminal length 0".  If this does not apply to your devices, then set this value to an empty string. Example:

set TERM_LENGTH_ZERO_CMD "".

2ND_LEVEL_ACCESS_CMD

The command that you would enter to go into a "priviledged" mode on the the device.  For some devices this concept does not apply as there are multiple usernames/passwords for different levels of access.  This variable will only be referenced if the "-ual 2" option is used on the command line when running the script.  Example for a UNIX system would be “su”

2ND_LEVEL_PASSWORD_PROMPT

The prompt that asks you for the second level password.  Again, this would only apply if the "-ual 2" option is used on the command line when running the script

Eg: “Password: “

2ND_LEVEL_PROMPT

Second level prompt character(s).  This is the character(s) usually following the device name when in 2nd level access mode.  An example using a Cisco router is

NY-router1#

So the value of 2ND_LEVEL_PROMPT would be "#"

Again, this would only apply if the "-ual 2" option is used on the command line when running the script.  If there is a "space" after this character, the space must be included!

E.g. "# "

ERROR_STRING

This is a character or string that will be displayed if an invalid command is sent to the device or the device rejects the command.  The program will only look for this character/string starting at the beginning of a line.  For example, on a Cisco device, if an errored command is entered, the error message will be written on a new-line beginning with the percent character (%).

Cisco Example:

NY_router1>show junk

          ^

% Invalid input detected at '^' marker.

 

NY_router1>

 

 

If you don't know what this error character/string is then make this value something you know will never come up when entering a command. For example, set it to "kdfjdkfjkj"

set ERROR_STRING "kdfjdkfjkj"

 

 

Sample Command: The following command will send the commands listed in file show_cmds.cmds to the devices listed in the file east_coast.rt. If there are any errors while issuing any of the commands, the script will immediately terminate because of the ssafe option (SuperSafe Mode) (Assuming the “ERROR_STRING” variable is correctly defined).  The script will not prompt the user for passwords because the passwords are being read in from the logins.txt file (-pw option).

 

generic_send_cmds -pw logins.txt rf east_coast.rt cf show_cmds.cmds ssafe