@@ -82,6 +82,14 @@ host = {
8282 // stream object used to respond to the timeout without having to close the connection
8383 // connection object gives access to close the shell using connection.end()
8484 },
85+ onError : function ( err , type , close ) {
86+ // optional code for responding to error
87+ },
88+ onClose : function ( has_error , command ) {
89+ // optional code for responding to close
90+ // has_error: boolean. True if error hapen
91+ // command: latest command that was processing when connection get closed.
92+ },
8593 onEnd : function ( notices , sshObj ) {
8694 // optional code to run at the end of the session
8795 // notices is array of all notices for each command.
@@ -147,34 +155,39 @@ dotenv.load();
147155var Email = require (' email' );
148156
149157var host = {
150- server: {
151- host: process .env .HOST ,
152- port: process .env .PORT ,
153- userName: process .env .USER_NAME ,
154- password: process .env .PASSWORD ,
155- passPhrase: process .env .PASS_PHRASE ,
156- privateKey: require (' fs' ).readFileSync (process .env .PRIV_KEY_PATH )
157- },
158- commands: [
159- " echo $(pwd)" ,
160- " cd ~/" ,
161- " ls -l" ,
162- " echo $(pwd)" ,
163- " ls -l" ,
164- ],
165- onCommandComplete : function ( notice , sshObj ) {
166- // confirm it is the root home dir and change to root's .ssh folder
167- if (notice .command === " echo $(pwd)" && notice .output .indexOf (" /root" ) != - 1 ) {
168- sshObj .commands .push (" cd .ssh" );
169- }
170- // we are listing the dir so output it to the msg handler
171- else if (notice .command === " ls -l" ){
172- console .log (notice .output );
158+ server: {
159+ host: process .env .HOST ,
160+ port: process .env .PORT ,
161+ userName: process .env .USER_NAME ,
162+ password: process .env .PASSWORD ,
163+ passPhrase: process .env .PASS_PHRASE ,
164+ privateKey: require (' fs' ).readFileSync (process .env .PRIV_KEY_PATH )
165+ },
166+ commands: [
167+ " echo $(pwd)" ,
168+ " cd ~/" ,
169+ " ls -l" ,
170+ " echo $(pwd)" ,
171+ " ls -l" ,
172+ ],
173+ onCommandComplete : function ( notice , sshObj ) {
174+ // confirm it is the root home dir and change to root's .ssh folder
175+ if (notice .command === " echo $(pwd)" && notice .output .indexOf (" /root" ) != - 1 ) {
176+ sshObj .commands .push (" cd .ssh" );
177+ }
178+ // we are listing the dir so output it to the msg handler
179+ else if (notice .command === " ls -l" ){
180+ console .log (notice .output );
181+ }
182+ },
183+ onClose : function ( has_error , command ) {
184+ // has_error is true if session has bin interrupted.
185+ // command is latest command that was processing and did not finish.
186+ console .log (command);
187+ },
188+ onEnd : function ( notices , sshObj ) {
189+ console .log (notices);
173190 }
174- },
175- onEnd : function ( notices , sshObj ) {
176- console .log (notices);
177- }
178191};
179192
180193// Create a new instance
0 commit comments