APC Command Sender

Top  Previous  Next

This program will send any number of commands to a list of APC devices. Since the APC device has a menu driven interface, the commands are primarily numbers that correspond to a particular action.  The commands that are sent are defined in a text file (any name), that you create.  The commands are sent in sequential order from top to bottom of the file.  Do not add the very last command to log off the router, the script will automatically handle that. 

 

Program Name: apc_send_cmds

 

Script Argument

Description

-rf <filename>

List of IP Address to run script against (REQUIRED)

-cf <filename>

File which contains a list of commands to send to APC devices.  One command per line.  Lines that begin with a “#” are considered comments and will not be sent to the router.  (REQUIRED)

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

 

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. For the APC device there are two special cases where the command in the text file is followed by a double colon (::) and then another string.  See the table below for more information.

 

The following table lists special commands can be entered in the command file.  See command looping and counter variables for more information on these.

(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

cmd::string

Send the command but don't look for the standard prompt for the APC device.  Instead, for after sending this one command only, the value of string will be the prompt the script waits to see.  This is necessary in the cases where you enter a command <number> and then the APC device prompts the user to enter in a new value for something (e.g. snmp community string, new syslog server, new ntp server, etc.)

cmd::ACCEPT

Send the command and then after the command is sent, verify that the command was successful.  This should be done when performing configuration changes such as change the snmp community string.  The script will specifically be looking for the string : Success in the display after the command is sent.

ESC

Send the escape character.  Must be all capitals.

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>

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

 

The following is a sample command file which changes the ntp server value.

 

########################################
# Commands with Special Meaning
# ESC - Send Escape character
# SLEEP <seconds>
#        e.g. SLEEP 5
3
3
2
##################################################
# Field Seperator is :: (two colons)
# If the second field does not contain the word
# ACCEPT, then it is the prompt that should be seen
# after that command is entered
##################################################
1::Primary NTP Server :
1.1.1.4
########################################################
# If we see ACCEPT in the second field then we need to
# check that the following is found in
# the buffer
# Accept Changes                 : Success
########################################################
6::ACCEPT
ESC
ESC
ESC

 

 

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 command will send the commands listed in file new_ntp_server.txt to the APC devices listed in the file apc_devices.txt. 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).  A log file will automatically be created with a unique file name that will not get overwritten (-ulog)

 

apc_send_cmds -ulog -pw logins.txt rf apc_devices.txt cf new_ntp_server.txt ssafe