ssh2shell 1.9.9 → 1.9.10
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 +1 -2
- package/lib/ssh2shell.js +3 -1
- package/package.json +1 -1
- package/src/ssh2shell.coffee +5 -3
- package/test/notificationstest.js +35 -9
package/README.md
CHANGED
|
@@ -139,8 +139,7 @@ host = {
|
|
|
139
139
|
commands: ["cd /var/logs", "ls -al", "msg:Listed dir", "cd /home/user"],
|
|
140
140
|
|
|
141
141
|
//Optional: Used by this.emit("msg", "my message") to output a message
|
|
142
|
-
msg: {
|
|
143
|
-
send: function( message ) {
|
|
142
|
+
msg: function( message ) {
|
|
144
143
|
console.log(message);
|
|
145
144
|
}
|
|
146
145
|
},
|
package/lib/ssh2shell.js
CHANGED
|
@@ -609,8 +609,10 @@
|
|
|
609
609
|
|
|
610
610
|
SSH2Shell.prototype._initiate = function(callback) {
|
|
611
611
|
this._removeEvents();
|
|
612
|
-
if (typeof this.sshObj.msg === 'function') {
|
|
612
|
+
if (this.sshObj.msg && this.sshObj.msg.send && typeof this.sshObj.msg.send === 'function') {
|
|
613
613
|
this.on("msg", this.sshObj.msg.send);
|
|
614
|
+
} else if (typeof this.sshObj.msg === 'function') {
|
|
615
|
+
this.on("msg", this.sshObj.msg);
|
|
614
616
|
} else {
|
|
615
617
|
this.on("msg", (function(_this) {
|
|
616
618
|
return function(message) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ssh2shell",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.10",
|
|
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",
|
package/src/ssh2shell.coffee
CHANGED
|
@@ -398,9 +398,11 @@ class SSH2Shell extends Stream
|
|
|
398
398
|
_initiate: (callback)=>
|
|
399
399
|
@_removeEvents()
|
|
400
400
|
|
|
401
|
-
if typeof @sshObj.msg == 'function'
|
|
402
|
-
@.on "msg", @sshObj.msg.send
|
|
403
|
-
else
|
|
401
|
+
if @sshObj.msg and @sshObj.msg.send and typeof @sshObj.msg.send == 'function'
|
|
402
|
+
@.on "msg", @sshObj.msg.send
|
|
403
|
+
else if typeof @sshObj.msg == 'function'
|
|
404
|
+
@.on "msg", @sshObj.msg
|
|
405
|
+
else
|
|
404
406
|
@.on "msg", ( message ) =>
|
|
405
407
|
console.log message
|
|
406
408
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var dotenv = require('dotenv').config()
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var sshObj1 = {
|
|
4
4
|
server: {
|
|
5
5
|
host: process.env.HOST,
|
|
6
6
|
port: process.env.PORT,
|
|
@@ -8,7 +8,7 @@ var sshObj = {
|
|
|
8
8
|
password: process.env.PASSWORD
|
|
9
9
|
},
|
|
10
10
|
commands: [
|
|
11
|
-
"
|
|
11
|
+
"msg: using msg.send",
|
|
12
12
|
"`All done!`",
|
|
13
13
|
],
|
|
14
14
|
msg: {
|
|
@@ -17,17 +17,43 @@ var sshObj = {
|
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
verbose: false,
|
|
20
|
-
debug: false
|
|
21
|
-
onEnd: function( sessionText, sshObj ){
|
|
22
|
-
//show the full session output. This could be emailed or saved to a log file.
|
|
23
|
-
this.emit("msg", "\nThis is the full session response:\n\n" + sessionText);
|
|
24
|
-
}
|
|
20
|
+
debug: false
|
|
25
21
|
};
|
|
26
22
|
|
|
23
|
+
var callback = function( sessionText, sshObj ){
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
|
|
27
27
|
//until npm published use the cloned dir path.
|
|
28
28
|
var SSH2Shell = require ('../lib/ssh2shell');
|
|
29
29
|
|
|
30
30
|
//run the commands in the shell session
|
|
31
|
-
var SSH = new SSH2Shell(
|
|
31
|
+
var SSH = new SSH2Shell(sshObj1);
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
var callback = function( sessionText, sshObj ){
|
|
34
|
+
|
|
35
|
+
//show the full session output. This could be emailed or saved to a log file.
|
|
36
|
+
this.emit("msg", "\nThis is the full session response: 2\n\n" + sessionText);
|
|
37
|
+
sshObj1.msg = function( message ) {
|
|
38
|
+
console.log(message);
|
|
39
|
+
}
|
|
40
|
+
sshObj1.commands = [
|
|
41
|
+
"msg: using msg",
|
|
42
|
+
"`All done!`",
|
|
43
|
+
]
|
|
44
|
+
var SSH = new SSH2Shell(sshObj1);
|
|
45
|
+
var callback = function( sessionText, sshObj ){
|
|
46
|
+
//show the full session output. This could be emailed or saved to a log file.
|
|
47
|
+
this.emit("msg", "\nThis is the full session response: 3\n\n" + sessionText);
|
|
48
|
+
sshObj1.msg = undefined
|
|
49
|
+
sshObj1.commands = [
|
|
50
|
+
"msg: using default msg",
|
|
51
|
+
"`All done!`",
|
|
52
|
+
]
|
|
53
|
+
var SSH = new SSH2Shell(sshObj1);
|
|
54
|
+
SSH.connect();
|
|
55
|
+
}
|
|
56
|
+
SSH.connect(callback);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
SSH.connect(callback);
|