All Products
Search
Document Center

Elastic Compute Service:Manage scripts

Last Updated:Jul 28, 2023

Workbench allows you to use script libraries to customize scripts. You can create routine tasks (such as running automated O&M scripts, polling processes, updating applications, and installing patches) and associate scripts with these tasks. Then, you can run the scripts to execute the tasks on Elastic Compute Service (ECS) instances. This topic describes how to create script libraries and scripts in Workbench.

Prerequisites

A Linux instance is created and is in the Running state.

Create a script library

Perform the following operations to create a script library. A script library can contain multiple scripts.

  1. In the top navigation bar, choose Features > Script Library.
  2. In the left-side navigation pane, click the Add icon to the right of All Scripts Libraries.
    Create a script library
  3. In the Create Script Library dialog box, configure the parameters described in the following table and click OK.
    ParameterDescription
    Script Library NameEnter a name for the script library.
    Script Library IconSelect the icon of the script library and the icon color for easy identification and classification.
    Script Library DescriptionEnter a description for the script library.
    Script Library SortingSet a priority for the script library.

    Scripts in different script libraries are executed based on the priorities of the script libraries. If multiple script libraries have the same priority, scripts in the script libraries are executed in the order of time when these script libraries were created.

    After the script library is created, you can view the script library in the left-side navigation pane. You can also modify or delete the script library, or add scripts to the script library as needed.

Create a script

After the script library is created, you must add scripts that you want to run to the script library. Perform the following operations to add scripts to a script library.

  1. In the top navigation bar, choose Features > Script Library.
  2. You can use one of the following methods to add scripts:
    Create scripts
    • ①: In the left-side navigation pane, click the Add icon to the right of the script library that you created.
    • ②: Click the script library. On the page that appears, click Create Script.
  3. In the Create Script dialog box, configure the parameters described in the following table and click OK.
    ParameterDescription
    Script LibraryBy default, the selected script library is displayed.
    Script NameEnter a name for the script.
    Script IconSelect the icon of the script and the icon color for easy identification and classification.
    Script TypeSelect a script type. Valid values: Bash Shell and Python.
    Script ContentEnter or paste the content of the script. You must check whether the syntax, logic, or algorithm associated with the script is correct.

    For example, if you enter ps -ef | grep java, you can run this script on an ECS instance to view all Java processes in the instance. For information about sample shell commands, see View instance configurations.

    Script DescriptionEnter a description for the script.
    Timeout Period (Seconds)Specify a timeout period for the script to be run on instances. Default value: 300. Unit: seconds. If a task that runs the script times out, the system forcefully terminates the task process.
    Sort Scripts BySet a priority for the script.

    Scripts in the same script library are executed based on their specified priorities. If multiple scripts have the same priority, the scripts are executed in the order of time when they were created.

    After the script is added to the script library, you can view the information of the script in the script list. You can also modify or delete the script as needed.