JUNOS Command Sender (jun_send_cmds)

Top  Previous  Next

The JUNOS commander sender is the as the cisco_send_cmds script except it used for Juniper devices running JUNOS.

 

This program will send any number of commands to a single JUNOS device or a list of JUNOS 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 script is different than the jun_config_cmds script in that this script is designed to send   non-configuration 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.  This script can also send configuration commands but the actual commands to enter and exit configuration mode, along with the "commit", must also be included in the list of commands to send. 

 

Note, for global JUNOS device configuration changes the jun_config_cmds script is the preferred tool as that script has more comprehensive error checking designed for configuration commands only. 

 

 

Program Name: jun_send_cmds

 

Script Argument

Description

-rf <filename>

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

or

-ip <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 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.  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 interface terse"

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

-ts

Display timestamp after entering each command on device.  Immediately after logging into the device, the script will issue the command "set cli timestamp".

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

 

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 be entered in the command file or on the command line and the script will automatically answer any additional confirmations or prompts.

(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

RETURN

Using the keyword RETURN is equivalent to sending just a carriage return or Enter key.  Not commonly used. 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

 

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 ospf neighbors
show interface
SLEEP 15
clear interface statistics all

 

 

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 1: The following command will send the commands listed in file show_cmds.cmds to the devices listed in the file rtrs.rt. 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 also save the output to a unique filename becasue 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).

 

jun_send_cmds -ulog -pw logins.txt -rf rtrs.rt -cf show_cmds.cmds -ssafe

 

Sample Command 2: The following script will send a "show tech" to the router 192.168.0.10. The output will be saved to the file show_tech_nyrtr1.log  The script will not prompt the user for passwords because the passwords are being read in from the logins.txt file (-pw option).

 

jun_send_cmds -log show_tech_nyrtr1.log -pw logins.txt -ipaddr 192.168.0.10 -cmd "request support information"

 

 

Sample Command 3: The following script will issue the command "show interface" 10 times, sleeping for 5 seconds between each time the command is entered.  The commands will be sent to the router 192.168.0.10. If there are any errors while issuing any of the commands, the script will immediately terminate because of the -safe option (Safe Mode).  The script will not prompt the user for passwords because the passwords are being read in from the logins.txt file (-pw option).

 

Note, the backslash at the end of each line will only work in a Linux/Unix shell.

 

jun_send_cmds -pw logins.txt -ipaddr 192.168.0.10 -safe \

       -cmd "LOOPSTART 10" \

       -cmd "show int | match error" \

       -cmd "SLEEP 5" -cmd LOOPEND