DeviceExpert Home | Online Demo

Automation Using Templates & Scripts

Overview

Quite often, there arises a need to carry out changes to the running configuration of devices and at times, same set of changes need to be applied to multiple devices. Though network administrators can very well edit the configuration manually, the task can prove to be arduous due to the volume of changes and the repetitive nature of the work. DeviceExpert provides a simple solution for this by way of 'Configuration Templates', 'Scripts' and 'Advanced Scripts'.

What are benefits of Custom Templates & Scripts?

How do Custom Templates & Scripts Work?

As the name itself implies, Custom Templates are the ones defined and created by the users themselves in accordance with their needs. A custom template contains the commands (provided by the user) to be executed on the device. A custom template can be created to configure any feature on a device. For instance, you can create a template to configure IGRP on a cisco router. The real power of a custom template lies in reusing the template across multiple devices for bulk configuration updates. For example, a single template could be used for changing the passwords of multiple devices many times. Similarly, a template for firmware upgrade could be used many times for many devices.

 

To enhance the reusability of a template, 'Template Variables' are defined. A template variable is a placeholder for a value. It can be specified when the template is uploaded to the device. After creating the template, when you wish to upload the changes to a particular device or a number of devices, you just need to provide the values for the template variables. Everything else is automatically taken care of by DeviceExpert.

 

Note: Creating 'Template Variables' is optional. You may create template variables if you want to enhance the reusability of the template.

 

Types of Custom Templates in DeviceExpert

Custom templates offered by DeviceExpert are of two types:

 

  1. TFTP Mode - for uploading a partial configuration change to a device/devices through TFTP.

  2. Script Execution Mode - commands are executed on the CLI console one after another. Script execution is divided further into two types as below -

 

The following table provides information about the each type of custom template and when to use them:

 

 

TFTP Mode

Simple Script Execution

Advanced Script Execution

TFTP mode is for uploading a partial configuration change to a device/devices through TFTP.

 

Example:

 

  • Enabling TELNET service

  • Changing SNMP Community

  • Forwarding Syslog messages

  • Changing the interface

 

In all the above case, TFTP mode of configuration upload could be used. In general, for carrying out changes to existing configuration, this mode could be used.

 

For other cases like executing a command on device, Script execution mode has to be used.

To execute a single command on the CLI console.

 

Example: Synchronizing Running & Startup Configurations. Through a single line in the script containing the command copy running-config startup-config, you can synchronize the startup and running configurations of any number of devices.

 

Other Examples:

 

  • Changing Passwords

  • Updating NTP Server Entries

  • Getting 'show version' output

To execute a series of inter-connected commands on a device in command line. After the execution of one command, some input has to be provided before the next command is invoked. In such a situation, advanced scripting would be useful.

 

When the execution of a command changes the prompt of the device or takes too much of time to execute or requires fine-grained control to track the flow, advanced script execution has to be used.

 

Example: Backing up your current IOS image to a TFTP server. To do this, the following sequence would be used:

 

  • Command to be used copy flash <filename> tftp
    <filename> - the location of your current IOS image

  • TFTP server's IP has to be specified

  • The file where it has to be copied, has to be specified

 

The above sequence of command execution could be transformed into an advanced script as below: (for details on advanced script, click here)

 

<command prompt=']?'>copy flash:/%SOURCE_FILE_NAME% tftp</command>

<command prompt=']?'>%TFTP_SERVER_IP%</command>

<command timeout='70'>%DESTINATION_FILE_NAME%</command>

 

Other Examples:

 

  • Uploading OS images / firmware upgrade

  • Configuring banner message
  • Resetting passwords of HP ProCurve and Exteme Summit devices
  • Deleting files from flash

 

Creating Custom Templates

To Create Custom Templates,

 

Guidelines for 'Advanced Script Execution Mode'

As stated above, the 'Advanced Script Execution Mode' is still more powerful as it provides the option to execute a series of inter-connected commands on a device in command line. To enable this, the commands to be executed are to be entered in specific format as detailed below:

 

Purpose

Syntax

Entering the commands to be executed in the command line

<command>xyz</command>
 

Example: <command>copy startup-config tftp</command>

Specifying the prompt that should appear after executing a command.

 

This can be used in the scripts for firmware upgrade, OS image backup etc.

<command prompt=']?'>xyz</command>
 

Example: <command prompt=']?'>copy startup-config tftp</command>

(Here, the prompt ? is placed within single quotes and following a closing square bracket)

 

 

Note: If prompt is not given, default prompt will be used

After executing a command, if you wish the application to wait for a few seconds, you can specify the time limit in seconds.  

 

This can be used in the scripts for firmware upgrade, OS image backup etc.

<command timeout='70'>copy startup-config tftp</command>

 

Example: <command timeout='70'>copy startup-config tftp</command>

Note: Default timeout is 30 seconds

After providing a response to query while executing a command, if the device does not expect the user to press "ENTER" after providing the response, this syntax has to be used

 

For example, when the device expects a response (say) 'Y' or 'N' alone and NOT an "ENTER" after that, this syntax has to be used.

 

This can be used in the scripts for firmware upgrade, OS image backup etc.

<command suffix='$NO_ENTER'>y</command>

 

Note: Default value for suffix is "ENTER", that is, new line

Specifying the prompt that should appear after executing a command.

 

This can be used in the scripts for firmware upgrade, OS image backup etc.

<command prompt='confirm'>xyz</command>

 

Example: <command prompt='confirm'>%DESTINATION_FILE_NAME%</command>

When the command sequence does not expect a response after the execution of a command, this syntax has to be used. This has to used coupled with a timeout value for waiting for sometime in between.

 

Example: This can be used for setting banner messages in Cisco devices

<command prompt='$NO_RESPONSE' timeout='5'>banner %DELIMITING_CHAR%</command>

 

Example: <command prompt='$NO_RESPONSE' timeout='5'>banner %DELIMITING_CHAR%</command>

You can automatically append hostname and timestamp for the files downloaded from the devices. This will help in pulling multiple context stack switch configuration information and store them as flat files under <DeviceExpert_Home>/tftp_files directory.

 

To do this, add the placeholder <HOSTNAME_TIMESTAMP> as shown in the example here.

<command prompt=']?'>copy running-config tftp:</command>

<command prompt=']?'>%TFTP_IP%</command>

<command>%File_Name%_<HOSTNAME_TIMESTAMP></command>

 

 

To apply changes using templates

    1. The list of all templates created by various users, are listed in the 'Custom Templates' page (Admin >> Device Management >> Custom Templates) along with other information such as who created the templates, description and timestamp of last modification.

    2. If the mode of execution chosen by you is TFTP, you will see the link 'Upload' under the column "Action". If the mode of execution is "Command Line" or "Advanced Script Execution", you will see the link "Execute"
       

To upload the template to device ,
 

 

 

Note:


(1) Command line script execution is not supported for the devices with the protocol 'SNMP-TFTP'

(2) The execution output of custom templates would be visible only to the users who executed the template. That means, users with the role 'Operator' and 'Power User' will be able to view the output of the custom templates that are executed by them. They will not be able to view the output of the templates executed by other users. Administrators will be able to view the output all the templates and they will also be able to delete the output.

 

Practical Applications of Command Line Script Execution

Command line script execution of custom templates would prove to be a powerful tool for various bulk operations on multiple devices. Following are few practical applications of the same.

Changing Passwords

You rotate the passwords on multiple devices at one go using the command line script execution. Following is the typical template content that could be used for this purpose:

 

configure terminal

enable password xxxx

exit

Getting 'show version' output of all devices

You can even execute various commands to get hardware information from a single device or multiple devices. For example, with just the following command in the script, you get 'show version' output for multiple devices at one go:

 

show version

Updating NTP server entries on your devices

If you wish to update NTP server details in many details, all that you need to do is to create a template as the one below:

 

configure terminal

ntp server x.x.x.x

exit

Synchronizing Running & Startup Configurations

Just through a single line in the script, you can synchronize the startup and running configurations of any number of devices.

 

copy running-config startup-config
 

or

 

copy startup-config running-config  

 

The above are just an indicative list to demonstrate how the scripts could be used. You may use it for a lot of other applications. Few more examples are available in our website. Please refer to them.

 

Some Practical Applications of Advanced Script Execution

Uploading OS images

Uploading of OS images/firmware is one of the commonest operations performed by the administrators. Advanced Script Execution can be used to upload the images. The image files can be transferred via TFTP.  

 

Following will be the sequence of command execution for OS image/firmware upload:

 

 

The above sequence of command execution could be transformed into an advanced script as below:

 

<command prompt=']?'>copy tftp: flash:</command>

<command prompt=']?'>%TFTP_SERVER_IP%</command>

<command prompt=']?'>%SOURCE_FILE_NAME%</command>

<command prompt='confirm'>%DESTINATION_FILE_NAME%</command>

<command timeout='120' suffix='$NO_ENTER'>y</command>

 

In the above example, placeholders have been used for Source File Name, TFTP Server IP and Destination File Name. At the time of executing this advanced script, values could be provided for these placeholders. The script could be used for many devices at one go.

Backing up your current IOS image to a TFTP server

To backup your current IOS image to a TFTP server, the following sequence would be used:

 

 

The above sequence of command execution could be transformed into an advanced script as below:

 

<command prompt=']?'>copy flash:/%SOURCE_FILE_NAME% tftp</command>

<command prompt=']?'>%TFTP_SERVER_IP%</command>

<command timeout='70'>%DESTINATION_FILE_NAME%</command>

 

In the above example, placeholders have been used for Source File Name, TFTP Server IP and Destination File Name. At the time of executing this advanced script, values could be provided for these placeholders. The script could be used for many devices at one go.

 

Configuring Banner Message

You can edit an existing banner message of a device or a group of devices using the advanced script execution. Users will be presented with this banner every time they attempt a connection with the device.

 

Normally, the desired banner message is entered within two delimiting characters. For example, within # and #. All the content between these two characters will appear as banner message. The delimiter will not be part of the banner message.

 

Following will be the sequence of command execution for configuring banner message:

 

 

The above sequence of command execution could be transformed into an advanced script as below:

 

<command>conf t</command>

<command prompt='$NO_RESPONSE' timeout='5'>banner %DELIMITING_CHAR%</command>

<command prompt='$NO_RESPONSE' timeout='5'>%BANNER_LINE_1%</command>

<command prompt='$NO_RESPONSE' timeout='5'>%BANNER_LINE_2%</command>

<command>%DELIMITING_CHAR%</command>

<command>end</command>

 

In the above example, placeholders have been used for Delimiting Character and Banner Message. At the time of executing this advanced script, values could be provided for these placeholders. The script could be used for many devices at one go.

Resetting the Passwords of HP ProCurve Devices

Using the 'Advanced Script Execution' mode, you can reset the passwords of HP ProCurve devices.

 

Following will be the sequence of command execution for resetting the password:

 

 

The above sequence of command execution could be transformed into an advanced script as below:

 

<command>conf t</command>
<command prompt='$NO_RESPONSE' timeout='5'>password manager</command>
<command prompt='$NO_RESPONSE' timeout='5'>%PASSWORD%</command>
<command prompt='$NO_RESPONSE' timeout='5'>%PASSWORD%</command>
<command>end</command>

 

In the above example, placeholders have been used for entering and confirming the new password. At the time of executing this advanced script, values could be provided for these placeholders. The script could be used for many devices at one go.

Deleting a file from flash

Cisco IOS images are stored in Flash memory. So, when you to install a new IOS image, you need to make sure your device has enough flash memory to support the image. In case, the device is running short of memory, you will have to delete the files from flash. This can be achieved using an advanced script.

 

Following will be the sequence of command execution:

 

 

The above sequence of command execution could be transformed into an advanced script as below:

 

<command prompt=']?'>delete flash:/%FILE_NAME%</command>

<command prompt='confirm'>%FILE_NAME%</command>

<command suffix='$NO_ENTER'>y</command>

 

In the above example, placeholder has been used for the name of the file to be deleted. At the time of executing this advanced script, value could be provided for this placeholder. The script could be used for many devices at one go.  

Scheduling Custom Templates

All the three types of custom templates - TFTP mode, script execution mode and advanced scripts could be scheduled for execution at a future point of time. Refer to the section under schedules for more details.

 

Managing Templates & Scripts

To view/edit a custom template,

If you to view the contents of an already created template or you want to edit the template,

 

    1. Go to "Admin" >> "Device Management" >> "Custom Templates" and click the name of the custom template to be viewed

    2. In the UI that opens, click 'Edit Template' and carry out the desired change and click 'Update'

To remove a custom template,

    1. Go to "Admin" >> "Device Management" >> "Custom Templates" and select the template(s) to be removed

    2. Click "Remove Template". The template would be removed permanently

 


© 2005-2007, ZOHO Corp. All Rights Reserved.