Note: Please go to to access the current RightScale documentation set. Also, feel free to Chat with us!
Home > Guides > RightScale API 1.5 > Examples > Instances > Run Executable

Run Executable

Runs a RightScript or Chef Recipe on an active RightScale Server.

icon-curl_api-v1.png    icon-right_api_client-v1.png

Table of Contents


Prerequisite:  Example assumes you have previously authenticated, and your valid session cookie is in 'mycookie'.

Basic Example


  • This is similar to Multi-Run Executable, but instead of running on a multiple active servers, this script updates only one server.
  • This can only be executed on a RightScale Server with an active instance (the INSTANCEID variable is the instance ID which can be retrieved from a call such as List Servers).
  • When specifying RightScale input(s), you must declare both the name and value.
  • The example below runs a RightScript. 
#!/bin/sh -e
INSTANCEID="9AOF4L3DC3IV4"  # Instance ID of the running instance. Obtain from the API
RIGHTSCRIPT="416366"        # RightScript ID to run.  Can get this from the API or the UI/URL.
curl -i -H X_API_VERSION:1.5 -b mycookie -X POST \
-d right_script_href=/api/right_scripts/$RIGHTSCRIPT \
-d inputs[][name]="DNS_DOMAIN_ID" \
-d inputs[][value]="text:9623906" \
-d inputs[][name]="DNS_RECORD_ID" \
-d inputs[][value]="text:ExampleRightAPI" \
-d inputs[][name]="RACKSPACE_API_TOKEN" \
-d inputs[][value]="cred:RACKSPACE_AUTH_KEY" \
-d inputs[][name]="DNS_RECORD_IP" \
-d inputs[][value]="text:public" \
-d inputs[][name]="RAX_REGION" \
-d inputs[][value]="text:ORD(Chicago)" \$CLOUD/instances/$INSTANCEID/run_executable

Sample Output

HTTP/1.1 202 Accepted
Server: nginx/1.0.15
Date: Fri, 21 Dec 2012 00:05:26 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Status: 202 Accepted
Location: /api/clouds/232/instances/9AOF4L3DC3IV4/live/tasks/ae-110022913001
X-Runtime: 2959
X-Request-Uuid: 31b3ee03337143b596fd70f457f47f82
Cache-Control: no-cache

Advanced Example

This example from rs_api_examples demonstrates running a recipe (also supports usage of API 1.0 from the CLI).

#!/bin/bash -e

# <server_or_instance_id> <recipe_name> [[extra curl post params]]

# e.g. 516031001 "rightscale::default" "server[ignore_lock]=true"
#       For API 1.5:
#       rs_api_version=1.5 rs_cloud_id=1869 1SR4O53A7PLFA "rightscale::setup_timezone" "inputs[][name]=rightscale/timezone" "inputs[][value]=text:Australia/Sydney"

[[ ! $1 ]] && echo 'No server_id ID provided, exiting.' && exit 1
[[ ! $2 ]] && echo 'No recipe name provided, exiting.' && exit 1

. "$HOME/.rightscale/"
. "$HOME/.rightscale/"

shift; shift
for arg in "$@"; do
	args+=(-d "$arg")

# needs all common public cloud IDs inserted or substitute with API call if possible
case "$rs_cloud_id" in 
    rs_cloud="AWS US-East"

case $rs_api_version in
    echo "Running Chef recipe [$recipe] on Server [$server_id]."
    echo "[API $rs_api_version] POST: $api_url"
    api_result=$(curl -s -S -i -X POST -b "$rs_api_cookie" -H X-API-VERSION:"$rs_api_version" -d server[recipe]="$recipe" "${args[@]}" "$api_url")
    case "$api_result" in 
      *Status:\ 201*)
        echo "$api_result" | awk '/^Location:/ { print $2 }'
        echo "FAILED: $api_result"
    echo "Running Chef recipe [$recipe] on Instance [$server_id] in cloud [$rs_cloud]."
    echo "[API $rs_api_version] POST: $api_url"
    api_result=$(curl -s -S -i -X POST -b "$rs_api_cookie" -H X-API-VERSION:"$rs_api_version" -d recipe_name="$recipe" "${args[@]}" "$api_url")
    case "$api_result" in 
      *Status:\ 202\ Accepted*)
        echo "$api_result" | awk '/^Location:/ { print $2 }'
        echo "FAILED: $api_result"

Sample Output

(includes the command issued)

$ rs_api_version=1.5 rs_cloud_id=1869 ./ 1SR4O53A7PLFA "rightscale::setup_timezone" "inputs[][name]=rightscale/timezone" "inputs[][value]=text:Australia/Sydney"
Running Chef recipe [rightscale::setup_timezone] on Instance [1SR4O53A7PLFA] in cloud [Softlayer].
[API 1.5] POST:


Prerequisite:  Example assumes you have previously authenticated using right_api_client.

Basic Example


  • This can only be executed on a RightScale Server with an active instance (the SERVERID variable is the server ID which can be retrieved from a call such as List Servers or by viewing the dashboard URL of the server).
  • The example below runs a RightScript.
  • When specifying RightScale input(s), you must declare both the name and value.


## Sets necessary variables for right_script_href and server ID and sets input names and values
script_href = "right_script_href=/api/right_scripts/500272003"
serverid = 920583003
## replace "INPUT1/2" and "VALUE1/2" with the name/value of your input accordingly
inputs = "&inputs[][name]=INPUT1&inputs[][value]=text:VALUE1&inputs[][name]=INPUT2&inputs[][value]=text:VALUE2"

## Runs the actual script/executable designated in script_href variable on the server
task = @client.servers(:id => serverid) + inputs)

## Shows the task summary, which is the same as the audit entry summary in the dashboard (failed, completed, etc.)

Sample Output


  • Sample output below comes from interactive Ruby shell (IRB) and uses sample script and server IDs. Your script HREF and server ID would be different in your own output.
  • is run 3 times to show the various "phases" of the script's execution on the server
script_href = "right_script_href=/api/right_scripts/500272003"
=> "right_script_href=/api/right_scripts/500272003"
serverid = 920583003
=> 920583003
inputs = "&inputs[][name]=INPUT1&inputs[][value]=text:VALUE1"
=> "&inputs[][name]=INPUT1&inputs[][value]=text:VALUE1"
task = @client.servers(:id => serverid)
=> #<RightApi::Resource resource_type="task">
=> "Querying tags"
=> "Preparing execution"
=> "completed: GB API Test"


See also

You must to post a comment.
Last modified
17:19, 12 Nov 2013


This page has no custom tags.


This page has no classifications.



© 2006-2014 RightScale, Inc. All rights reserved.
RightScale is a registered trademark of RightScale, Inc. All other products and services may be trademarks or servicemarks of their respective owners.