The Workbench Script Library is a script management tool that is built into Workbench. You can use it to save frequently used commands or script snippets to the cloud and run them with a single click in any Workbench instance session.
For example, you can run scripts to check the system load, deploy applications, or clean up logs with a single click.
Key advantages include the following:
Improve efficiency: For repetitive operations and maintenance (O&M) tasks, you can save long commands as scripts and run them with a single click. This reduces repetitive work and speeds up operations.
Standardize operations: Ensure that operations on different instances are consistent and standardized. This helps maintain a consistent environment and reduces issues caused by manual input errors.
Convenient management: You can store and manage your personal scripts in a central location. You can also import existing commands directly from Cloud Assistant to reuse your scripts.
Create a script
You can create scripts in the Script Library in two ways.
Create a script directly
Log on to a Linux instance using Workbench or log on to a Windows instance using Workbench.
In the Workbench interface, click
in the navigation pane on the left to open the Script Library.In the Script Library panel, click
to create a new script.In the Create Script dialog box, configure the following parameters.
Script Name: Enter a clear and descriptive name for the script, such as "Check System Load".
Script Type: Select
Shell,Bat, orPowerShellbased on the scripting language and the operating system of your instance.Script Content: Paste the script code into this area.
Example of Shell script content (for Linux):
#!/bin/bash # Check system load, memory, and disk usage echo "========== System Load ==========" uptime echo "========== Memory Usage ==========" free -h echo "========== Disk Space Usage ==========" df -hAfter you complete the configuration, click Save.
Import a script from Cloud Assistant
If you have already created frequently used commands in Cloud Assistant, you can quickly import them into the Script Library.
In the Script Library panel, click
to import Cloud Assistant commands.In the command list that appears, select one or more commands to import.
Click Import. The selected commands are added as new scripts.
Run a script
Log on to a Linux instance using Workbench
For Windows instances, you must log on using Session Manager to run scripts in the PowerShell interface. You cannot run scripts from the Script Library if you connect using a direct terminal connection (RDP).
In the Workbench interface, click
in the navigation pane on the left to open the Script Library, and then find the script that you want to run.Click
to the right of the target script.In the Run Script dialog box, click Run, or create a file and run it.
Run: This mode simulates manual input by pasting the script content into the current terminal line by line. This mode is suitable for running a simple sequence of independent commands.
Create file before running: This mode saves the entire script content as a temporary file on the server and then runs the file. This is the recommended method for running standard scripts.
To ensure that the script runs as expected, we recommend that you select the Create file before running mode for any multi-line script.

FAQ
Why might a script from the Workbench Script Library fail to run?
The script type does not match the operating system of the instance.
The script contains errors.
The current user does not have the required permissions to run the commands in the script.
Where is the Script Library saved? Can I still use it if I switch computers?
Yes, you can. The Script Library is stored in Alibaba Cloud and linked to your Alibaba Cloud account. The library is automatically synchronized for an account and its Resource Access Management (RAM) users. Therefore, you can use the Script Library even if you switch computers.