Scripts
The Scripts page displays information about all existing scripts. You can create, modify, or copy a script. After a script is created, you can create an execution task for the script. Alternatively, you can create a task and execute and view it on the Tasks page. Each script supports up to 20 versions. Each user can create up to 1000 script versions.
Creating a Script
- Log in to the AOM 2.0 console.
- In the navigation pane, choose Automation (Retiring). The Automation page is displayed.
- In the navigation pane, choose Scripts and click Create Script in the upper right corner.
- Set parameters by referring to Table 1.
Figure 1 Creating a script
Table 1 Script information description Category
Parameter
Description
-
Script Name
Name of a script. Enter up to 64 characters. Only letters, digits, and underscores (_) are allowed.
Version
Version of the script. Enter the actual value.
Enterprise Project
Select the enterprise project to which the script belongs.
Script Description
Description of the script. Enter up to 1000 characters.
Script
- Manually enter commands. Currently, Shell, BAT, PowerShell, and Python scripts can be executed. A script can contain up to 30,000 bytes.
NOTE:
- Shell and Python scripts can be executed only on Linux hosts.
- BAT and PowerShell scripts can be executed only on Windows hosts.
- The UniAgent reads the standard output of the script and writes it into logs. The print() output of Python has a cache and may not be updated to the standard output in real time. As a result, the execution logs of the Python script cannot be updated in real time. To output Python logs in real time, use any of the following methods:
- Use sys.stdout.flush() to print the output.
- Use sys.stderr.write() to print the output.
- Use print(message.flush=True) to print the output.
- After setting the parameters, click Check for High-Risk Commands. High-risk commands undergo regular expression verification. If the verification fails, risks may occur. For details about high-risk commands, see Table 1.
Execution Policy
Batch Release
Specifies whether to enable batch release. By default, this function is disabled.
Instances for Each Batch
Number of instances on which tasks can be executed at the same time.
Interval
Interval for executing each batch of tasks.
Review
Review
Specifies whether to enable manual review. By default, this function is disabled.
You can only modify the review configuration by modifying the atomic service card in the tool market.
Reviewer
After manual review is enabled, you need to select a reviewer.
Alternatively, create a topic and add a subscription on the SMN console to notify a reviewer.
- Manually enter commands. Currently, Shell, BAT, PowerShell, and Python scripts can be executed. A script can contain up to 30,000 bytes.
- Click Save.
Releasing a Script
After a script is created, it is in the Unreleased state. The script task can be executed only after the script is released.
- In the navigation pane, choose Scripts. On the version management page, locate the row that contains the target version and click Release in the Operation column.
Figure 2 Releasing a script
- On the release confirmation dialog box that is displayed, click Yes.
Executing a Script
After a script is released, you can execute the script task on the script list page. Script execution depends on the UniAgent capability. You need to ensure that the UniAgent has been installed and is running on the ECS where the script is to be executed.
- In the navigation pane, choose Scripts. On the script management page, locate the target script and click Execute in the Operation column.
- Specify Script Parameters, Timeout Duration, and Execution Account. You can also select Sensitive for script parameters. If Sensitive is selected, the entered content will not be explicitly displayed in the script parameter box.
Figure 3 Script parameters
- Select target instances.
- Click Add. The instance selection page is displayed.
- For Instance Type, the default value is ECS. For Method, the default value is Specific. For details about the methods, see Table 2.
Figure 4 Adding instances
Table 2 Selection method description Selection Method
Description
Specific
Enter search criteria and select instances from the instance list. By default, instances are searched by name.
By filter
- Enter filter attributes and values to search for instances.
- If there are multiple filter criteria, the search is performed based on the AND relationship.
- This method also takes effect for instances added later.
By tag
- Set tag keys and values, and specify one or more tags to select instances.
- If there are multiple tags, the search is performed based on the AND relationship.
- This method also takes effect for instances added later.
From CMDB
Enter search criteria or keywords and select instances from CMDB. There are two types of nodes:
- Static: Select an ECS under a specified CMDB application.
- Dynamic: Select a node in the CMDB application to dynamically obtain ECSs under the node. This method also takes effect for instances added later.
- Click OK.
- Click Execute. On the task execution page that is displayed, view the task execution status.
You can also click Save. The created task is displayed on the task management page for subsequent task execution or other operations.
More Operations
After the script is created, you can view the script name, version, and creation time on the script list page. You can also perform the operations listed in Table 3.
Operation |
Description |
---|---|
Managing a script version |
Click Manage Version in the Operation column. On the version management page that is displayed, view and modify the script version information and execute the script as required. |
Copying and creating a script |
On the version management page, click Copy and Create in the Operation column of a released or unreleased script and copy the original script content to create a script. |
Managing an unreleased script |
On the version management page, click Release, Modify, or Delete in the Operation column of a script that has never been released. A script can only have one released version. Tasks associated with an unreleased version cannot be executed. After the version is released again, the tasks can be executed. |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot