Execute Bash Script
Overview
The Execute Bash Script action allows users to run Bash scripts on a Linux agent, supporting both locally stored scripts and user-provided script content. This action enables flexible management of automation tasks, such as system updates, log management, and custom application deployments directly from the bot workflow. By using this action, you gain control over the script content on the agent system, making it easier to manage and automate deployment processes.
Prerequisites
Linux Agent
- If the
run_as_user
parameter is set to a non-root user, ensure that this user has the appropriate permissions to perform the tasks required by the script.
How to Use This Action?
To use the Execute Bash Script action, follow these steps:
-
In your bot workflow, go to Linux Actions under the Library section.
-
Search for Execute Bash Script and drag it into your workflow.
-
Select the Linux integration that is connected to the agent where the script will run.
-
Under the Parameters section, specify the required parameter values according to your requirements. For more details, refer to the Parameter Details section.
-
Specify the following parameters based on your script source:
Running Local Script
- is_local_script: Set this parameter to
True
to indicate that the script is located on the agent. - local_script_path: Provide the path to the local script on the agent.
Running Provided Script
- is_local_script: Set this parameter to
False
to provide the script content directly. - script_content: Enter the script content. You can either:
-
Manually input the script content.
-
Use AI assistance to generate the script.
-
- Save or update the bot, then click on Run to execute the bot. View the results in the execution details to confirm successful execution or troubleshoot if there are any errors.
Parameter Details
Parameter | Required | Description |
---|---|---|
is_local_script | No | Indicates if the script is stored locally on the agent (True ) or provided directly as content (False ). |
local_script_path | Conditional | The path to the local script on the agent (required if is_local_script is True ). |
script_content | Conditional | The content of the script to execute (required if is_local_script is False ). |
run_as_user | Yes | Specifies the user under which the script executes (default value is "ubuntu"). |
execution_timeout | Yes | Maximum time (in seconds) allowed for script execution (default is 600 seconds). |
Example Use Case
Scenario: Log Management
Suppose you need to perform routine log management, such as cleaning up logs older than a certain number of days. You can use Execute Bash Script to run a custom cleanup script stored on the agent or provide the script content directly.
Sample Script for Log Cleanup:
The following is an example of a script that deletes log files older than 7 days from the /var/log
directory:
#!/bin/bash find /var/log -type f -name "*.log" -mtime +7 -exec rm -f {} \; echo "Old logs deleted successfully."