# OCI tech-specific script execution

> Run ad hoc scripts on OCI instances using OCI's native command execution mechanism

---

Site [llms.txt](/llms.txt)

---

In Cloud Management Platform (CMP), this is an alternative to SSH, controlled by a server parameter. When enabled, ad hoc scripts are executed by the [Oracle Cloud Agent](https://docs.oracle.com/en-us/iaas/Content/Compute/Tasks/manage-plugins.htm) running on the instance rather than over an SSH connection.

<div class="alert alert-info" role="alert">


This method provides additional security; however, due to the Oracle Cloud Agent's polling interval, it is slower than SSH.
</div>


## How it works

The Oracle Cloud Agent polls for queued commands approximately every 90 seconds. When CMP submits a script to run on an OCI server with tech-specific script execution enabled, the command is added to the Oracle Cloud Agent's queue. The agent picks up the command on its next poll, executes the script, and returns the output.

## Prerequisites

Before using tech-specific script execution, ensure the following are in place:

### SSH key

An SSH key must be associated with the image used to provision the server. Servers provisioned from that image inherit the key.

#### Create an SSH key

1. Open a terminal and run:

   ```bash
   ssh-keygen -t rsa -b 4096 -m PEM -f ~/.ssh/cloudbolt_oci -C "cloudbolt-oci"
   ```

1. Display and copy the private key value:

   ```bash
   cat ~/.ssh/cloudbolt_oci
   ```

#### Add the private key to CMP

1. Go to **Admin** > **SSH Keys**.
1. Select **New SSH Key**.
1. Provide a name and paste the key material.
1. Select **Add**.

#### Associate the key with the image

1. Go to the OCI resource handler.
1. Open the **Images** tab.
1. Under **Credentials** for an image, select to add or edit credentials.
1. Provide the **Username**.

   <div class="alert alert-info" role="alert">


   CMP will attempt to use this username when performing actions on servers provisioned using this image.
   </div>


1. Leave the **Password** field empty.
1. Under **Key name**, select the SSH key.
1. Select **Save**.

### Public IP address

A public IP address is required on the instance to install the Oracle Cloud Agent.

### Server compartment

<div class="alert alert-warning" role="alert">


OCI does not allow tech-specific script execution on instances in the root compartment.
</div>


To use OCI's native command execution mechanism, instances must be in a sub-compartment. Running scripts via SSH will still work at the root level.

### Oracle Cloud Agent

<div class="alert alert-info" role="alert">


For existing servers provisioned without an SSH key, you must have an alternative means of SSH access before installing the Oracle Cloud Agent.
</div>


The instance must have the Oracle Cloud Agent installed and running. SSH into the instance using the key pair assigned to its image, then run the following:

```bash
# Install the agent
sudo yum install -y oracle-cloud-agent

# Enable and start
sudo systemctl enable oracle-cloud-agent
sudo systemctl start oracle-cloud-agent

# Verify
sudo systemctl status oracle-cloud-agent
```

## Enable tech-specific script execution

Enable the **Use Tech-Specific Script Execution** parameter at the server or environment level.

### Server level

Enable the parameter on existing servers.

1. Locate the server in CMP.
1. Open the **Parameters** tab.
1. Select **Add**.
1. Locate the **Use Tech-Specific Script Execution** parameter.
1. Select the parameter, then select **Next**.
1. Set the value to `True` and select **Save**.

### Environment level

Enable the parameter at the environment level to automatically apply it to new servers provisioned in that environment.

1. Go to **Admin** > **Environments**.
1. Select the environment.
1. Open the **Parameters** tab.
1. Select **Add**.
1. Locate and select the **Use Tech-Specific Script Execution** parameter.
1. Select **Add**.
1. Under **Options**, select to edit the parameter options.
1. Select **True** from the dropdown, then select **Add option**.
1. Select **Save**.

## Run an ad hoc script

1. Go to the server in CMP.
1. Select **Ad Hoc Script**.
1. Enter your script (for example, `whoami` or `date`).
1. Select **Run**.

CMP checks the job state every 10 seconds. Expect up to 3 minutes for the job to complete. States progress from `Visible` → `Accepted` → `Acknowledged` → `Succeeded` / `Failed`. Script output is available once the job reaches `Succeeded`.
