ssh2-executor
Advanced tools
Comparing version
{ | ||
"name": "ssh2-executor", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Execute one or more commands on the target machine by ssh2 and reduce results.", | ||
@@ -24,3 +24,6 @@ "main": "ssh2exe.js", | ||
"ssh2": "^0.5.0" | ||
}, | ||
"devDependencies": { | ||
"optimist": "^0.6.1" | ||
} | ||
} |
@@ -11,1 +11,36 @@ # ssh2-executor | ||
### Usage | ||
``` | ||
const Executor = require('ssh2-executor'); | ||
Executor.run({object} argv, {Array} commands, {function} reduce); | ||
``` | ||
* `argv` {object} SSH2 connection options: | ||
* `host` {string} Default: localhost | ||
* `port` {number} Default: 22 | ||
* `username` {string} Default: administrator | ||
* `password` {string} Default: null | ||
* `commands` {Array} Commands to execute | ||
* `reduce` {function} Reduce function takes next parameters: | ||
* `resutls` {Array} Result outputs according to commands | ||
* `timing` {object} total beg, end ms | ||
### Example | ||
Execute `whoami` and `hostname` commands on the target machine, compare with the expected values and out boolean answer: | ||
```javascript | ||
'use strict'; | ||
const argv = require('optimist').argv; | ||
const Executor = require('ssh2-executor'); | ||
Executor.run(argv, [ | ||
'whoami', | ||
'hostname' | ||
], (results, t) => { | ||
console.log(/^administrator\s?/.test(results[0]) && /^SuperMachine\s?/.test(results[1])); | ||
console.log(`Execution Time ${t.end - t.beg} ms`); | ||
}); | ||
``` | ||
Output: | ||
``` | ||
true | ||
Execution Time 923 ms | ||
``` |
5573
34.16%6
20%55
19.57%46
318.18%1
Infinity%