Remote Script

Execute a script on each remote Endpoint.

Remote Script

Remotescript executes a script on each remote Endpoint in the current server list. There are blocks that execute before and after the script is executed respectively. These blocks execute once for each Endpoint in the current Endpoint list.

During the execution, there is an implicit serverloop (psloop). The Endpoint object is pushed onto the stack, any “pre” block is executed, the specified script is then executed on the current remote Endpoint and then any “post” block is executed. In the post block, the variable $? is set to the exit status of the script.

remotescript requires named parameters as follows:

Parameter Description
filepath Mandatory: A full path to the script to be executed on the remote Endpoint.
params Optional: A list of parameters to be passed to the script.

Example 1

Execute a script on each Endpoint in the current target Environment:

remotescript(filepath: "/path/to/file");

Example 2

Execute a script on each Endpoint which has the attribute “ATT1” set to “Y”:

if ($ATT1 = "Y") {

// This filters the current Endpoint list to those with //ATT1 set to Y. "remotescript" will now only execute on // those Endpoints.

remotescript(filepath: "/path/to/file");

}

Example 3

Execute a script specific to each Endpoint type within the Environment:

if (${server.type} = "windows") {

// Filters the _Endpoint_ list to those of type "windows"

remotescript(filepath: "C:\myapp\myscript.bat");

}

if (${server.type} = "unix") {

// Filters the _Endpoint_ list to those of type "unix"

remotescript(filepath: "/opt/scripts/myscript.sh");

}

Example 4

Execute a script on each Endpoint in the Environment, passing parameters:

set p = {"first\_param","$ATT"};

remotescript(filepath: "C:\myapp\myscript.bat", params: $p);

Example: Executing a script on each _Endpoint_ in the _Environment_, with pre and post block processing:

set p = {"first\_param","$ATT"};

remotescript(filepath: "C:\myapp\myscript.bat", params: $p) {

pre {

// pre block

echo "Running script on _Endpoint_ ${server.name}";

}

post {

// post block

echo "exit status is $?";

}

}

NOTE: An Environment needs to be on the stack before the remotescript is executed. This sets the initial Endpoint list. During a deployment (or if a stand-alone action is being invoked from a selected Environment) then the Environment is on the stack and the Endpoint list will be set to the members of that Environment. A runtime error will result if an Environment cannot be found on the stack.