Run shell commands
This guide runs an arbitrary shell command through the proxy, using the Command execution mode. Prefer running scripts when the set of operations is known in advance; see Execution modes for the trade-off.
Prerequisites
- The proxy is installed and running inside your network.
- A Proxy account with execution mode Command, connected to an exec-mode profile on the proxy.
Get started walks through the equivalent setup for script mode; for shell commands, configure
the profile with
"mode": "exec"instead (see Configuration).
Configure the shell
The profile determines which shell executes the commands (powershell, unix, or cmd), together with the
working directory and the environment variables the command receives:
{
"name": "windows-commands",
"active": true,
"mode": "exec",
"token": "<your-token>",
"key": "<your-secret-key>",
"automator_url": "<the Automator URL copied from the account>",
"shell": "powershell"
}
All options are described in the configuration reference.
Send a command from a package
A package sends the complete command line to execute:
const result = executeOnProxy("windows-commands", {
command: "Get-Service -Name W32Time",
});
log(result.data.stdout);
Optionally, parameters can carry an extra string that is appended to the command line:
const result = executeOnProxy("windows-commands", {
command: "Get-Service",
parameters: "-Name W32Time",
});
The result contains the command's output in data.stdout and data.stderr; err is set when the execution failed.
See executeOnProxy for the full description.