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.
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.
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).
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:
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); ).
--------- 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>
OmniVista built-in variables are listed below.
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.
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.
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:
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.
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.
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.
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.)
Select an option from the drop-down menu (User Switch Picker/Use Topology) and click on the Add/Remove Devices button to select devices..
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.
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.
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.
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.