Proxy
The proxy functions can be used to run shell commands or predefined scripts inside a remote network through the automator Proxy.
executeOnProxy
Executes a shell command or a predefined script on the proxy connected to a Proxy account.
const result = executeOnProxy(account, data);
The shape of data depends on the execution mode of the account:
- Script mode:
{ script, parameters }
Wherescriptis the name of a script configured on the proxy andparametersis an optional object with named parameter values. Parameter names must match the profile'sparamsentries exactly, including the-or--prefix, because the name is placed on the command line as the flag. A parameter with valuenullis passed as a bare flag without a value, for switch parameters. - Command mode:
{ command, parameters }
Wherecommandis the shell command to execute andparametersis an optional string appended to the command line.
The result object contains the following fields:
data: the result of the execution, containing thestdoutandstderrof the executed process and itsexit_code.
When the complete output is valid JSON it is parsed, and the field contains the resulting value instead of a string. Otherwise the field contains the raw output as a string, with the trailing newline removed. This applies to bothstdoutandstderr.err: the error message when the execution failed, otherwisenull.info: additional error details, otherwisenull.
The following problems throw an error, and the call does not return a result object:
- Invalid calls: the account is not a Proxy account, or the payload does not match the account's execution mode.
These are rejected by the automator itself; nothing is sent to the proxy. - Connection errors: the automator cannot reach the proxy, or the response cannot be decrypted with the account's key.
- Timeouts: with the pull transport mode, the call throws when the proxy does not deliver a result within 5 minutes, so long-running scripts must finish within that window.
Problems detected by the proxy itself do not throw. The call returns normally and err describes the problem:
- The script or command ran but failed.
The process output is still available indata, including theexit_code, andinfocontains further details. Whether a non-zero exit code counts as a failure depends on the profile's shell: with theunixandcmdshells it setserr, but with thepowershellshell the call is reported as successful, so packages must checkdata.exit_codethemselves. - The script is not configured on the proxy's profile, or a parameter is not in the profile's
paramslist. - The payload contains a
commandwhile the profile uses the script execution mode. - The token or execution mode does not match the proxy's profile, indicating a mismatch between the account and the proxy configuration.
Example:
Run a shell command on an account with the Command execution mode and log its output:
const result = executeOnProxy("windows-proxy", {
command: "Get-Service -Name W32Time",
});
log(result.data.stdout);
// => Status Name DisplayName
// ------ ---- -----------
// Running W32Time Windows Time
Example:
Run the createUser script configured on the proxy of an account with the Script execution mode, passing named parameters, and
handle a failed execution:
const result = executeOnProxy("script-proxy", {
script: "createUser",
parameters: { "-Name": "jdoe", "-Department": "Finance" },
});
if (result.err) {
log("createUser failed:", result.err, result.data.stderr);
} else {
log("created:", result.data.stdout);
// => created: User jdoe created in department Finance
}
The Run scripts and Run shell commands guides show how to configure the proxy side of these calls.