Modernizing Scripts into the Cloud

Looking back at Lake Tahoe
OCI Console — compute instance, Oracle Cloud Agent
Run a command from OCI Console in Compute Instance

Create Command on OCI Compute

See the documentation here for creating a command on the compute instance. We will use this REST endpoint in an OCI Data REST task, the first step is defining the POST method and the URL.

Create a REST task in OCI Data Integration
Parameterize the URL — make it resuable
Content-Type: application/jsonAccept = application/json
Define the headers in REST task

Define the create command payload

The payload for the create command has a number of parameters including the compartment where the command is created, the name for the jobs, the instance to run the job on and the script to run. The output can be saved to Object Storage, below we are just reporting to standard output.

{  "compartmentId": "${COMPARTMENT_ID}", "executionTimeOutInSeconds": 3600,  "displayName": "${COMMAND_NAME}",  "target": {    "instanceId": "${INSTANCE_ID}"  },  "content": {    "source": {      "sourceType": "TEXT",     "text": "${SCRIPT_TEXT}"    },    "output": {      "outputType": "TEXT"    }  }}
Define the request payload in the REST task

Getting Status of Command

Extract the command id from the create command above;

Define an expression to get the command id from the response
Define the polling status check REST endpoint

Canceling the Command

Cancel/delete the command using the COMMAND_ID expression and the REST endpoint to DELETE the command;

Define the cancel REST endpoint

Poll and Success Conditions

Finally we have to define the polling and success conditions.

CAST(json_path(SYS.RESPONSE_PAYLOAD, '$.lifecycleState') AS String) != 'SUCCEEDED' AND CAST(json_path(SYS.RESPONSE_PAYLOAD, '$.lifecycleState') AS String) != 'FAILED'

Orchestrating the Command

We can execute the REST task from within OCI Data Integration and also schedule this so that we can do this over and over. Below we have a task schedule which executes a REST task, the task schedule can configure any parameters to specific values also!

Schedule the command to run on cadence


Here we have seen how we can modernize existing scripts in the cloud and how we can automate tasks that are time consuming and need to be performed over and over again. Hopefully this gives you some good insight into running scripts, tools and commands on OCI. Let me know what you think.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
David Allan

David Allan


Architect at @Oracle developing cloud services for data. Connect on Twitter @i_m_dave