ssh2shell 2.0.2 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -47
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -219,75 +219,31 @@ Usage:
|
|
|
219
219
|
Connecting to a single host:
|
|
220
220
|
----------------------------
|
|
221
221
|
|
|
222
|
-
*How to:*
|
|
223
|
-
* Connect using a key pair with pass phrase.
|
|
224
|
-
* Use sudo su with user password.
|
|
225
|
-
* Set commands.
|
|
226
|
-
* Test the response of a command and add more commands and notifications in the host.onCommandComplete event handler.
|
|
227
|
-
* Use the two notification types in the commands array.
|
|
228
|
-
* Use msg: notifications to track progress in the console as the process completes.
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
*.env*
|
|
232
|
-
```
|
|
233
|
-
HOST=
|
|
234
|
-
USER_NAME=
|
|
235
|
-
PRIV_KEY_PATH=~/.ssh/id_rsa
|
|
236
|
-
PASS_PHRASE=myPassPhrase
|
|
237
|
-
```
|
|
238
222
|
|
|
239
223
|
*app.js*
|
|
240
224
|
```javascript
|
|
241
|
-
var dotenv = require('dotenv').config(),
|
|
242
|
-
Email = require('email');
|
|
243
|
-
|
|
244
225
|
var host = {
|
|
245
226
|
server: {
|
|
246
227
|
host: "192.168.0.1",
|
|
247
228
|
userName: "myuser",
|
|
248
|
-
password: "sudoPassword",
|
|
249
229
|
passPhrase: "myPassPhrase",
|
|
250
230
|
privateKey: require('fs').readFileSync("~/.ssh/id_rsa")
|
|
251
231
|
},
|
|
252
232
|
commands: [
|
|
253
233
|
"`This is a message that will be added to the full sessionText`",
|
|
254
234
|
"msg:This is a message that will be displayed during the process",
|
|
255
|
-
"echo $(pwd)",
|
|
256
|
-
"sudo su",
|
|
257
|
-
"msg:changing directory",
|
|
258
235
|
"cd ~/",
|
|
259
|
-
"ls -l"
|
|
260
|
-
|
|
261
|
-
"echo $(pwd)",
|
|
262
|
-
"msg:Command dynamically added",
|
|
263
|
-
"ls -l",
|
|
264
|
-
"`All done!`"
|
|
265
|
-
],
|
|
266
|
-
|
|
267
|
-
onCommandComplete: function( command, response, sshObj ) {
|
|
268
|
-
//confirm it is the root home dir and change to root's .ssh folder
|
|
269
|
-
|
|
270
|
-
if (command === "echo $(pwd)" && response.indexOf("/root") != -1 ) {
|
|
271
|
-
//unshift will add the command as the next command, use push to add command as the last command
|
|
272
|
-
sshObj.commands.unshift("msg:The command and response check worked. Added another cd command.");
|
|
273
|
-
sshObj.commands.unshift("cd .ssh");
|
|
274
|
-
}
|
|
275
|
-
//we are listing the dir so output it to the msg handler
|
|
276
|
-
else if (command === "ls -l"){
|
|
277
|
-
this.emit("msg", response);
|
|
278
|
-
}
|
|
279
|
-
},
|
|
236
|
+
"ls -l"
|
|
237
|
+
]
|
|
280
238
|
};
|
|
281
239
|
|
|
282
|
-
|
|
283
|
-
//Create a new instance
|
|
284
240
|
var SSH2Shell = require ('ssh2shell'),
|
|
285
241
|
SSH = new SSH2Shell(host);
|
|
286
242
|
|
|
287
|
-
//use a callback
|
|
288
243
|
var callback = function (sessionText){
|
|
289
244
|
console.log (sessionText);
|
|
290
245
|
}
|
|
246
|
+
|
|
291
247
|
SSH.connect(callback);
|
|
292
248
|
```
|
|
293
249
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ssh2shell",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"author": "cmp-202",
|
|
5
5
|
"description": "A wrapper class for ssh2 to run multiple sequential commands in an SSH shell session, handle command responses, and tunnel through to other hosts using nested host objects",
|
|
6
6
|
"main": "./lib/ssh2shell.js",
|