Alcatel-Lucent OmniVista Cirrus

Network Management as a Service

CLI Script

The CLI Scripting CLI Script Screen displays a list of all configured CLI Script Files. It is also used to create, import, edit, and delete, script files, and send script files to network devices. A CLI Script File is a text-based file used to configure one or more devices through OmniVista's CLI Scripting feature. CLI Scripting is especially useful in applying batch updates or common configurations across multiple devices. When a script file is applied, each command in the file is sent to the device. A user can create a CLI Script that is only available to that user, or can create a "shared" script that is available to any network administrator.

Note: Before attempting to send a script, OmniVista Cirrus must know the CLI/FTP user name and password for each device being configured. If necessary, go to the Managed Devices Screen in the Inventory application to specify CLI/FTP user name and password. You can also specify the CLI/FTP user name and password using the "Device - Edit Device" operation in the Topology application.

Note: You cannot send scripts to APs.

Pre-Configured Scripts

OmniVista includes pre-configured CLI Script Files, which are displayed in the CLI Script List (along with any user-configured scripts). These pre-configured scripts are "shared" scripts and are available to any network administrator. A brief description of each script, as well as the contents of the script file, are provided in the Details Panel for the script. Click on a script in the CLI Script List to view script details.

Important Note: Use caution when using the shadmin_Ewebimageclean script. Use the Resource Manager application to perform a full backup on the switch prior to an upgrade.

Creating a Script File

Click on the Create icon. Enter a Filename for the script (e.g., show_switch). The file extension ".script" will be added automatically when the script file is saved. Select the Shared Admin Script checkbox to create a "shared" script that can be used by network administrators. If you do not select the checkbox, the script will only be available to you. When a "shared" script is created, the prefix "shadmin" is automatically assigned to the filename. To add a description of the script that will appear in the Details Panel, enter the description as follows at the top of the script. For example:

<js>
/* @@Enter a description here@@*/

Enter the commands to be applied to the switch via this script in the Commands field. Enter one command per line. The script can be a combination of  both CLI commands and JavaScript. You can also define variables, or use OmniVista built-in variables to be used in the script. Note that if a script with the same name currently exists, an error message will appear. Re-name the script and continue as described above. Verify that the syntax of all the commands is correct, then click the Add button. The filename will be listed in the CLI Script List in alphabetical order. Select the script in the CLI Script List and click on the Send Script button to send the script to a network switch(es).

CLI and Java Scripts

Scripts can be a combination of both CLI commands and JavaScript. The following is an example of a CLI script containing JavaScript:

---------   script start -------------
<js>
var devtype = cli.deviceType();
if (devtype.indexOf("OS68") > -1)
cli.sendCmd("ls");
else if (devtype.indexOf("OS62") > -1)
cli.sendCmd("dir");
else
cli.sendCmd("files");
if (devtype.indexOf("OS68") > -1)
{
cli.setTimeout(3, 30);
cli.sendCmd("show log swlog");
}
else if (devtype.indexOf("OS66") > -1)
{
cli.setTimeout(5, 0);
cli.sendCmd("show log swlog");
}
cli.trace("I got: " + cli.lastResponse() );
cli.sendCmd("ls " + "$USERVAR" ); /* user defined variable! */

</js>
---------   script end -------------

Notice in the above example, the usage of the variable ‘cli’ . This is a built-in variable that can be used within the scripting blocks. CLI offers the following functions:

  • sendCmd( String cmd ) allows the user to send a CLI command to the switch.
  • lastResponse() returns a string that represents the switch output from the last command the user sent to the switch (whether the command was sent via JavaScript or just entered as CLI in the cli script itself). deviceType() returns the same string as can be seen via the Topology applications “Type” column.
  • setTimeout(minutes, seconds) allows a caller to specify a hint to the CLI Scripting application about how long it could take for the next command to return a response. In the example above, the JavaScript specifies a timeout of 3 minutes and 30 seconds to apply to the next command (show log swlog) if the device is something like an OS6800-48. It specifies 5 minutes if the device is something like an OS6624. Some commands can be slow in returning output to the CLI Scripting/SSH session, so this can help prevent the scripting session from timing out before a response is received. Once the session is receiving a response from the command (e.g., show log swlog), the default timeout will be automatically reset. The user specified timeout does not take affect for the entire session, just the CLI command used after the call to setTimeout(minutes, seconds). You may specify "0" for minutes or seconds according to what is needed. Negative numbers are converted to '0' internally, thus ignored.

If both minutes and seconds contain either "0" and/or negative numbers, the timeout request will be ignored. Therefore the minimum timeout will be 1 second (ex: cli.setTimeout(0, 1);   ).

  • trace( String message ) logs any arbitrary string passed as its ‘message’ argument to the CLI Scripting Audit Log. Can be contained in a variable for instance.
  • expectPrompt( String prompt ) sets-up the particular script (running on whatever devices) to expect a prompt that is not in the default collection of expected prompts. In other words, it allows the user to temporarily add to the set of prompts that CLI Scripting is hard-coded to recognize.
  • deviceType() returns a string that contains the device’s type as seen in the Topology application.
  • cliSleep(milliseconds) allows the user to set a time, in milliseconds, before the next CLI command is executed.
  • errorLog(String message) logs any ‘error’ argument to the CLI Scripting Audit Log. Can be contained in a variable for instance.
  • cli.sendCmd(more) by default, the switch will stop running a command at a confirmation prompt and wait for the user to confirm the action.   The 'more' command tells OmniVista to expect a specific prompts(s) and continue running the script. For example, the 'more' variable should be used when sending a script to reload the working directory (reload working no rollback-timeout). In the example below, the 'more' command tells OmniVista to expect the "Confirm Activate" and "Confirm New Activate" prompts, and to reload the switch from the Working Directory in 10 minutes.

---------   script start -------------

<js>

cli.sendCmd("more");

cli.expectPrompt("Confirm Activate (Y/N) :");

cli.expectPrompt("Confirm New Activate (Y/N) :");

cli.sendCmd("reload working no rollback-timeout in 10:10");

cli.sendCmd("y");

</js>

---------   script end -------------

Enter only one command per line. Operational commands that automatically issue a confirmation prompt and require the user to type a response (such as, Y or N) are not supported in CLI script files. Examples include takeover, reload, fsck, etc. Do not attempt to include these command types in the script file. Instead, manually issue them via the standard CLI command line prompt. These operations can also be issued on a device-by-device basis via WebView or OmniVista.

Important Note: If a command that takes a long time to complete (e.g., “write memory flash-synchro” ) , is issued as the last command in a CLI script, the session can end right after the command is issued, ending the session before the command is executed. To avoid this problem, either add another command at the end of the script ( “show chassis” ), or add a tapps timeout. For example, the following command sets a timeout of 0 minutes and 15 seconds:

<tapps> set timeout 0 15 </tapps>

Built-In Variables

OmniVista built-in variables are listed below.

  • $BASE_MAC - Replaced automatically with target base MAC address.
  • $BOOT_DIR - Replaced automatically with target boot directory (ex: working).
  • $CHASSIS_TYPE - Replaced automatically with target chassis type.
  • $IP_ADDRESS - Replaced automatically with target switch IP address.
  • $LOGIN_ID - Replaced automatically with target CLI/FTP User Name.
  • $LOGIN_PWD - Replaced automatically with target CLI/FTP Password.
  • $READ_PWD - Replaced automatically with target community string for SNMP reading.
  • $SECOND_PWD - Replaced automatically with the value of secondary password for the device, if applicable. The secondary password for a device is set in the Edit Discovery Manager Entry window in the Inventory application.
  • $SYS_LOCATION -   Replaced automatically with the location of the device as defined in sysLoction MIB-II variable.
  • $SYS_NAME - Replaced automatically with the name of the device as defined in sysName MIB-II variable.
  • $SYSTEM_OID - Replaced automatically with target unique object ID.
  • $SYS_VERSION - Replaced automatically with the MPM Version of the device as displayed in OmniVista.
  • $WRITE_PWD - Replaced automatically with target community string for SNMP writing.
  • cli.forgetPrompt() - This CLI script directive is used to reverse the cli.expectPrompt() directive, providing a way to ignore prompts that interfere with script execution.

Important Note: If you are using Built-In variables within a Java Script , the variable must be contained within quotes (e.g. " $BASE_MAC" ). If you are using Built-In variables outside of a Java Script, the quotes are not required.

Script Directives

A tag, called <tapps> allows certain directives to the CLI Scripting application. <tapps> does not use a scripting engine. It is a set of supported commands that tell the CLI Scripting application how to handle certain actions. For example, a user may write the following CLI script that uses all of the supported <tapps> commands:

<tapps> set timeout 5 </tapps>
qos apply
<tapps> import another.script </tapps>
<tapps> second password </tapps>

set timeout: The above script specifies a timeout for the qos apply command. It performs the same function as the previous Java Script example, but the user does not need to specify seconds. However the user must always specify minutes (the minutes can be "0" if the user wants to specify the timeout only in seconds).

Examples:
As shown above, to set a timeout of 5 minutes, only the minutes parameter is required:
<tapps> set timeout 5 </tapps>
qos apply

To set a timeout of 15 seconds, you must first specify 0 minutes , then 15 seconds :
<tapps> set timeout 0 15 </tapps>
qos apply

To set timeout of 5 minutes and 15 seconds, you would enter:
<tapps> set timeout 5 15 </tapps>
qos apply

Note: The set timeout command only applies to the next command in the script (e.g., qos apply ). Thereafter, the timeout reverts back to its default.

import script: The import script directive tells the CLI Scripting application to insert the commands from the specified script at that spot in the current script. This allows re-use of scripts by other scripts. In the example above, if the CLI Scripting application script named "another.script" contained only the command 'ls' , then 'ls' would be inserted at runtime at that point in the current script. The log output for a running of the current script would show the command 'qos apply' sent, followed by the command 'ls' being sent. Detection of loops takes place at strategic points in the CLI Scripting application on both the client and server sides.

second password: The second password directive tells the CLI Scripting application to prepare to send the password again. Some devices have a second login capability that requires the use of a second password. This second password for a given device is set by the user via Topology when a device is selected for Editing. The value in the Topology 'Secondary Password:' field will be used by this new <tapps> feature as the password to set when or if the device prompts for a password.

last command: On some devices (e.g., OA5510-TE), commands such as 'reload' will 'hang' the OmniVista CLI Scripting session because the switch session will end without closing the session with OmniVista. The 'last command' directive, <tapps> lastcmd </tapps>, alerts OmniVista that the next command is the last command and a response may not be received after this command. OmniVista will gather whatever response is given before reload and close the session. For example:

<js>
cli.sendCmd("enable");
cli.sendCmd("$SECOND_PWD");
cli.expectPrompt("Do you want to save config before rebooting (y/[n])");
cli.expectPrompt("Do you really want to reboot the Chassis (y/[n])");
</js>
reload
n
<tapps> lastcmd </tapps>
y

The expectPrompt() calls in the java scripts train the CLI Script to send the next value upon receiving the specific prompt from the switch. Note that 'lastcmd' is used before “Y” and not reload command.

Importing a Script File

Although OmniVista allows users to manually create script files within the CLI Scripting application, existing script files can also be imported. In other words, a file containing a set of CLI commands can be accessed from a server or local drive and then applied to one or more devices. This allows users to maintain a library of network configurations and then apply them to devices in their network as needed. Before importing a file to one or more devices, consider the following important guidelines:

  • Any script file being imported must be text-based (ASCII).
  • Although file extensions such as .txt and .ascii are supported, the file extension .script is recommended.
  • All CLI commands contained in the file must be supported on the device. Also, operational commands that automatically issue a confirmation prompt and require the user to type a response (such as, Y or N) are not supported in CLI script files. Examples include takeover , reload , fsck , etc.
  • CLI commands must also be entered into the text file one command per line .
  • Only one script file can be imported at a time.

To import a script file, click the Import Script button at the top of the screen. On the Import Script window, click on the Browse button to locate the file. Select the file and click on the Import button, then click Finish. The script will be imported as a "shared" script with the current date appended to the script name (e.g., new_script20161026.script).

Note: If you are browsing for a file with an extension other than .script , be sure to select Files of Type -> All Files in the dialog box.

Editing a Script File

Select the script in the CLI Script List and click on the Edit icon. Edit the script commands and click on the Apply button. Note that you cannot edit the script name or "shared" status. If you want to change the "shared" status of script, delete the script and re-create it.

Important Note: When the changes are saved, the previous contents of the script file are overwritten. To preserve the original contents of the file, be sure to make a backup copy before editing.

Sending a Script File

You can send a script file to a single device or multiple devices in the network. Select a script in the CLI Script List and click on the Send Script button to bring up the Send Script Wizard. Complete the screens as described below.

Script Info

The name and contents of the selected script file are displayed. Click Next. (Note that you have the option of selecting a different script. Click on the Browse button to bring up all of the scripts in the CLI Script List, select a script and click OK, then click Next.)

Device Selection

Select an option from the drop-down menu (User Switch Picker/Use Topology) and click on the Add/Remove Devices button to select devices..

  • Use Switch Picker - Select the devices and click OK. Click Next.
  • Use Topology - The Topology application will launch in the Physical Map view. Select the device(s),then click on the OK button at the bottom of the Detail Panel to return to the Send Script Wizard. The devices will appear in the list of devices. Click Next.

Scheduler

You can send a script immediately to the selected device(s), or schedule the script to be run at a specific time or at regular intervals. After selecting/configuring an option, click Next.

  • Now - The script will be sent immediately to the selected device(s).
  • Periodically - Schedule a recurring script as described below. Set the Start and End Time to configure how long the recurring script will be sent, then a "Simple" schedule or " Cron" job to set the intervals.
    • Start Recurrence From Client Time -Select Enable and set a start date (and time) for the recurring script. This configures the start date and time for "Simple" jobs and the start date for "Cron" jobs. The Cron job start time is configured in the "Execute At Server Time" field.
    • End Recurrence At Client Time -Select Enable and set a start date and time for the recurring script. Select Disable to continue sending the scrip indefinitely. This configures the end date and time for both "Simple" jobs and "Cron" jobs.
    • Simple - Select this option to configure a simple repeating script. Set an Interval using the Days/Hours fields, and enable the Repeat field to the number of times to repeat the script until the configured "End Recurrence At Client Time" is reached.
    • Cron - Select this option to schedule a recurring cron job to send the script.
      • Execute At Server Time - Select the time when you want to begin the cron job. This is the OmniVista Server time (Pacific Time) (e.g., 12:00 AM).
      • Recurrence Pattern - Select the interval for a recurring cron job.
        • Daily - The script will be sent every day at the configured start time. By default, the script will be sent every day ("Every 1 Day").
        • Every Day(s) - Customize a daily script by entering the number of days you want to sent the script during the month (Range = 1 - 30 days). For example, you could enter "2" to send the script every other day.
        • Weekly - The script will be sent once a week on the selected day at the configured start time. Select the day of the week on which you want the script to be sent. The script will be sent every week on that day. You can select more than one day to send the script on multiple days of the week.
        • Every Weekday - The script will be sent every day of the week at the configured start time.
        • Monthly - The script will be sent monthly on the configured day at the configured start time.
          • Select the first radio button to schedule the script for a specific day of the month, and number of months. By default, the script will be sent on the first day of every month ("Day 1 of every 1 Month"). However, you can customize it. For example, you could schedule the script for the 15th day every other month ("Day 15 of every 2 Months").
          • Select the second radio button and select a number (e.g., First, Second) day (Weekday, Monday, Tuesday) and number of months. By default, the script will be sent on the first day of every month ("First Day of every 1 Month"). However, you can customize it. For example, you could send the script the Second Tuesday of every other month "The Second Tuesday of every 2 Months").

Define User Variables

If there are variables within the script, the Define User Variables Screen is displayed. Click in field next to the variable and enter value to be used. After completing all of the variable fields, click the Send Script button at the bottom of the screen.

Deleting a Script File

Select the Script File in the CLI Script List and click on the Delete icon. Click OK at the confirmation prompt. Note that when a file is deleted, it is permanently removed from the scripting_files directory, and cannot be recovered.

CLI Script Details

The CLI Script List displays basic information about all configured CLI Scripts stored on the OmniVista Server. Click on a script to view the commands contained in the script.

  • File Name - The script Filename.
  • Shared Admin Script - Whether or not the script is a shared script (True) or not (False).
  • Description - A brief description of the script.
  • Commands - The commands contained in the script.