Updated on 2026-06-23 GMT+08:00

Creating a Script

Standardized common O&M scripts are provided. COC provides public scripts for server initialization, log clearing, and health check, enabling O&M personnel to quickly invoke and optimize the scripts. If the provided public scripts do not meet your service requirements, you can create custom scripts. Custom scripts support Shell, Python, and Bat commands. You can set input parameters for the scripts. By properly designing script logic and parameter configurations, you can ensure that custom scripts not only meet specific requirements, but also improve O&M efficiency and strengthen security.

Constraints

The maximum size of the script content is 100 KB.

Creating a Custom Script

  1. Log in to COC.
  2. In the navigation pane, choose Resource O&M > Automated O&M.
  3. In the Routine O&M area, click Script Management. The script management page is displayed.
  4. On the displayed Custom Scripts tab page, click Create Script.
  5. Set basic script information by referring to Table 1.

    Table 1 Basic information parameters

    Parameter

    Description

    Script Name

    Create a script name based on the naming rules.

    The value can contain 3 to 100 characters, including letters, digits, hyphens (-), and underscores (_).

    Enterprise Project

    Select the enterprise project to which the script belongs from the drop-down list.

    After the script is created, the enterprise project cannot be modified.

    Version

    The default version number is 1.0.0. You can specify the script version number. The version number format is x.x.x.

    Risk Level

    Select High, Medium, or Low based on service requirements.

    Description

    Enter a description about the script.

    The value can contain 1 to 256 characters.

  6. Set the script content by referring to Table 2.

    Table 2 Script content description

    Parameter

    Description

    Script Type

    The script type can be Shell, Python, or Bat.

    After the script is created, the script type cannot be changed.

    Script Content

    Enter the script content.

    • The interpreter declaration is automatically added to the first line of the script.

      For example, if you select the Python script, #!/usr/bin/python is automatically added to the first line.

      This format depends on the system's Python soft link. If the link is missing or invalid, you need to manually update it to the path of the local Python interpreter.

    • (Optional) Scripts that define input parameters will pass and utilize them according to the chosen script type.
      • In Shell scripts, parameters can be referenced as ${parameter-name}.
      • In Python scripts, parameters can be retrieved from environment variables via the os module in Python's standard library, for example, varValue = os.getenv('parameter-name').
      • In Bat scripts, they can be referenced as %parameter-name%.

    Verify High-Risk Command

    You can perform high‑risk command detection on scripts.

    NOTE:

    The verification results from high‑risk commands serve only as a reference when determining a script's risk level. The tool does not automatically block a script if its assigned risk level differs from the verification outcome. Risk levels should be evaluated based on the actual impact on services.

    • Verification scope: the high-risk commands involved in the verification. You can click High-Risk Commands to view the verification rules.
    • Verification rule: Within the verification scope, the script content is matched with high-risk commands using regular expression matching.
    • Verification result: The regular expression is used to verify whether the script content is high-risk, low-risk, or medium-risk.

  7. (Optional) Set script input parameters by referring to Table 3.

    Table 3 Script input parameter description

    Parameter

    Description

    Script Input Parameters

    Add execution parameters of the script. A maximum of 20 parameters can be added, and the parameter value can contain spaces.

    Sensitive

    You can select the Sensitive check box to encrypt the parameters.

    After this check box is selected, the parameters are desensitized for display and encrypted for storage.

  8. (Optional) Configure parameters in the Advanced Settings area by referring to Table 4.

    Table 4 Additional settings description

    Parameter

    Description

    Manual Review

    After this function is enabled, the script needs to be reviewed. For details about how to review the script, see Reviewing a Custom Script.

    Reviewer

    Select Shift or Individual.
    • Shift: Select a shift scenario and a role from the drop-down lists based on the configured values. For details about how to configure a shift, see Shift Schedule Management.
    • Individual: Select a user as the reviewer. For details about how to configure a reviewer, see Personnel Management.

    Notification Mode

    Select a notification method from the drop-down list.
    • Default: The notification method selected in the subscription notification settings of the reviewer is used by default. For details about how to set the default notification method, see Selecting a Notification Method.
    • SMS, WeCom, DingTalk, Phone, Lark, and Email: Notifications are sent based on the information reserved by the reviewer. For details about how to set the reviewer information, see Modifying Personnel Information.
    • No notification: The system does not notify any recipient.

  9. Click OK. The custom script is created.

    After the script is created, you can view the basic information about the script in the script list and perform operations such as reviewing, modifying, executing, and deleting the script. For details, see Managing Scripts.

Helpful Links

  • Custom and public scripts can be executed periodically. For details, see Scheduled O&M.
  • The COC script management feature enables the standardized, online modification of ECS hostnames. For details, see Changing the ECS Hostname Using a Script.
  • You can use COC to create, review, modify, execute, and delete scripts, and manage tags by calling APIs. For details, see Script Management.