Hi
I was reviewing your use of ssh2shell and saw that you have three incorrect entries on your host object.
connectedMessage:true,
readyMessage:true,
closedMessage:true,
These are string parameters so to set them to return nothing do the following:
connectedMessage:"",
readyMessage:"",
closedMessage:"",
To use the default messages for these events remove those three settings for the host object.
I noticed the msg and onCommandComplete is building its own allSessionText which is duplicating core ssh2shell functionality. Most of onCommandComplete should be removed.
Recommended code change:
SSH2Utils.prototype.runMultiple = function(server,cmds,cmdComplete,then){
server.userName = server.username || server.userName || server.user;
log.silly(pkg.name, '%s@%s:%s',server.userName,server.host,server.port);
log.silly(pkg.name, '%j',cmds);
var host = {
server:server,
idleTimeOut:1000,
commands: [].concat(cmds), // very important to clone
msg: {
send: function( message ) {
log.verbose(pkg.name, 'send '+message );
}
},
onCommandComplete: function( command, response, sshObj ) {
cmdComplete(command, response, server);
},
onEnd: function( sessionText, sshObj ) {
log.silly(sessionText);
}
};
var SSH = new SSH2Shell(host);
SSH.connect();
};
Notes:
- sessionText is SSH2SHELL's allSessionText. Every commpeleted command response is appended to sessionText and is handled in the onEnd event for each host object. There is no need to create your own as it should show command and prompt as well as the command stdout.
- msg.send is a callback used in the handling of "msg: some text" commands in your command array and is intended to output to the terminal running the script or back to chat if using with a hitchat bot like gits hubot to provide progress messages as the script runs not for session text.
- Session text messages uses the "
some text" format in you array of commands, anthing within the single quotes is appended to sessionText.
- onCommandCommplete: when this event fires there is always a command so testing for it is redundant and as I said that detail is already added to sessionText. The array splitting and joing of response also seems redundant and if you have a case where stdout from the session is containing garbage or you require different formating it might be better to do a replace on the sessionText using a regular expression.
Hi
I was reviewing your use of ssh2shell and saw that you have three incorrect entries on your host object.
These are string parameters so to set them to return nothing do the following:
To use the default messages for these events remove those three settings for the host object.
I noticed the msg and onCommandComplete is building its own
allSessionTextwhich is duplicating core ssh2shell functionality. Most of onCommandComplete should be removed.Recommended code change:
Notes:
some text" format in you array of commands, anthing within the single quotes is appended to sessionText.