Updated on 2025-08-12 GMT+08:00

Executing Public Scripts

Scenarios

Public scripts are predefined scripts. You can clean disks, reset passwords, start or stop OSs with this function. You can only read and execute public scripts.

Precautions

Ensure that you have the permission on the component to which the target VM belongs when executing a script.

Notes and Constraints

A maximum of 999 instances can be selected for a task.

Executing a Public Script

  1. Log in to COC.
  2. In the navigation pane on the left, choose Resource O&M > Automated O&M.
  3. In the Routine O&M area, click Script Management.
  4. Choose Public Scripts.
  5. Locate the script to be executed and click Execute in the Operation column.
  6. Set Script Input Parameters.

    • Script Input Parameters: The parameters are preset in public scripts and cannot be modified. The script input parameter values can be set manually or selected from the parameter center. Currently, disk cleansing is not supported. You can manually specify parameter values or select a preset parameter value from the parameter center. Select the region where the parameter is located, parameter name, and parameter association mode.
      Figure 1 Manually specifying script parameters
      Figure 2 Selecting script parameters from the parameter center

      Table 1 Parameter association modes

      Parameter Association Mode

      Description

      Use the latest parameter value in the corresponding environment

      This parameter is used during script execution. The value is the latest parameter value obtained from the corresponding region in the parameter center in real time.

  7. Set Executed By and Timeout Interval.

    • Executed By: root is set by default. It is the user who executes the script on a target instance node.
    • Timeout Interval: 300 is set by default. It indicates the timeout interval for executing the script on a single target instance.

  8. Click Add and configure the parameters on the Select Instance dialog box.

    Table 2 Instance parameters

    Parameter

    Description

    Example Value

    Selection Method

    Select an instance selection method.

    • Manual Selection: Manually select an instance based on Enterprise Project, View Type, Resource Type, Region, and Target Instance.

    Manual Selection

    Enterprise Project

    Select an enterprise project from the drop-down list. You can choose All.

    All

    View Type

    Select a view type.

    • CloudCMDB resources: Select an instance from the resource list.
    • CloudCMDB application groups: Select an instance from the application group list.

    CloudCMDB resources

    Resource Type

    The value can be ECS or BMS.

    ECS

    Region

    Select a region from the drop-down list.

    CN-Hong Kong

    Target Instance

    Set filter criteria in the filter box and select the filtered instances.

    -

  9. Configure Batch Policy and Suspension Policy.

    • Batch Policy: Select Automatic, Manual, or No Batch.
      • Automatic: The selected instances to be executed are automatically divided into multiple batches based on the preset rule.
      • Manual: You can manually create multiple batches and add instances to each batch as required.
      • No Batch: All instances will be executed in the same batch.
    • Suspension Policy:
      • You can set the execution success rate. When the number of failed hosts reaches the number failed ones that are calculated based on the execution success rate, the service ticket status becomes abnormal and the service ticket stops being executed.
      • The success rate ranges from 0 to 100 and supports accuracy up to one decimal place.

  10. Click OK. On the displayed page, click OK.
  11. Perform the following operations to check whether a service ticket execution is complete.

    • For the service tickets that are being executed:
      • If you want to pause the next batch when the current batch is executed, click Pause in the upper right corner.
      • If you want to continue the paused batch, click Continue in the upper right corner.
      • If you want to stop the service ticket that is about to be executed or is abnormal, click Forcibly End.
    • For the service tickets that are executed:
      • If some or all instance tasks in the service tickets are executed abnormally:
        1. Click the Abnormal tab in the Execution Information area. Locate an abnormal batch and click Retry in the Operation column.
        2. Click the Abnormal tab in the Execution Information area. Locate an abnormal batch and click Cancel in the Operation column.
      • If all instance tasks in the service tickets are executed successfully, no more operation is needed.