RemoteExec
Execute a command on a remote machine (without installing a D2 agent)
- Type
- javascript
- Pack
- CommonScripts
Source
//Execute a command on a remote machine
var output = [];
var localSystem = false;
for (var s = 0; investigation.systems && s < investigation.systems.length; s++) {
if (investigation.systems[s].name === args.system) {
localSystem = true;
break;
}
}
var params = localSystem ? {system: args.system, cmd: args.cmd} : {using: args.system, cmd: args.cmd};
var entries = executeCommand("ssh", params);
var ret = entries[0];
if (ret === null) {
output.push({ContentsFormat: formats.text, Type: entryTypes.error, Contents: "Failed to execute remote command."});
} else {
result = ret.Contents;
if (!result.success) {
output.push({ContentsFormat: formats.text, Type: entryTypes.error, Contents: result.error});
} else {
output.push({ContentsFormat: formats.text, Type: entryTypes.note, Contents: result.output});
}
}
return output;
README
Executes a command on a remote machine (without installing a D2 agent).
Script Data
| Name | Description |
|---|---|
| Script Type | javascript |
| Tags | endpoint |
Dependencies
This script uses the following commands and scripts.
- ssh
Inputs
| Argument Name | Description |
|---|---|
| system | The name of system on which to run the command. |
| cmd | The command to run. |
Outputs
There are no outputs for this script.