Closed Kurtas closed 8 years ago
I would expect it to detect the E1>
prompt by default as >
is one of the default chars used in the regular expression match string. I would not tend to used debug, verbose and event handlers firing with every character through the stream, just about, then writing to console log with every event. Gets a bit messy when you do get output but also complicates the fault finding process I think. Verbose is a good starting point, if you need more info about what internal process SSH2shell is getting to then use debug. I only use event handlers when I am processing more complex command structures and response handling. In most cases verbose will give you the event information you are looking for.
Could you try this and post the result:
var host = {
server: {
host: '10.0.11.34',
port: 22,
userName: 'cisco',
password: 'cisco'
},
commands: [
"msg:Doing something",
"show clock",
"sh ip int brief",
],
msg: {
send: function (message) {
console.log(message);
}
},
};
//Create a new instance
var SSH2Shell = require ('ssh2shell'),
SSH = new SSH2Shell(host);
//add global event handlers to the SSH instance
SSH.on('end', function (sessionText, sshObj) {
console.log("End event: " + sessionText);
});
//Start the process
SSH.connect();
Result:
debian@dev1:~/js/node_modules$ node test2.js
Connected
Ready
Timeout error: 10.0.11.34: Command timed out after 5 seconds
Closed
End event: Connected to 10.0.11.34
E1>
debian@dev1:~/js/node_modules$
Excellent, can you turn on debugging please and post the result. Would you also be able to confirm which version of ssh2shell you are using
I'm using ssh2shell@1.4.1
Result (with enabled debug) is same like in previous post. I can give you direct access to the cisco for you IP and you can try it by yourself.
Hi, Sorry I meant to do this last night but I forgot. The first problem was that there is no white space after the last prompt char.
In lib\ssh2shell.js on line 273-275 add a ? after each \s so it becomes:
this.passwordPromt = new RegExp("password.*" + this.sshObj.passwordPromt + "\\s?$", "i");
this.passphrasePromt = new RegExp("password.*" + this.sshObj.passphrasePromt + "\\s?$", "i");
return this.standardPromt = new RegExp("[" + this.sshObj.standardPrompt + "]\\s?$");
I will put this fix in with a couple of other changes but that will get it going in the mean time.
Second problem:
The commands run correctly when I test except the last exit command when closing the stream. Once the all commands run the last thing it does is run stream.end('exit');
which is supposed to write the sting to the stream and then close the stream but instead its causing a timeout to trigger.
The output from the session shows that EA1>e
or EA1>ex
is the last text at prompt. If I add 'exit' to the command array it will run the command and the session will terminate but that probably wont work if connecting through more than one host of this type (ssh tunneling).
Temp fix: Add 'exit' as your last command for now.
I need to look into it more to determine why the stream.end command is stalling before I can provide a solid fix. If I can do some testing over the next couple of days on your host as my virtual machines (Linux) don't do it.
Thanks,
Andrew
Hi Andrew,
thanks for your time & fix. Certainly try everything what you want, it's test version of the cisco.
Thanks, Mirek
Hey @cmp-202 I was having an issue where some commands were not executing on Palo Alto Networks firewalls and would just timeout. The issue ended up being that the firewall would reply back to the client with some data and then a line saying:
[24;1H[Klines 1-9 [m
which I realized was something you actually see in the CLI when there is too much data to display at one time and you have to hit the space bar to get the next page of data to show. Eventually all the data will be displayed if you keep hitting space bar.
I am not sure if there is anything that can be added to the library to help with this behavior. However, I was able to workaround this. A normal command that would never complete look like this:
commands: [ "show jobs all" ]
by changing the command to:
commands: [ "show jobs all | match ." ]
the command doesn't try to page through data and gives it all back to you and the command completes.
Hopefully this helps someone else.
Thanks for the library :+1:
Interesting hadn't encountered paging but I can see how that would cause problems.I probably wouldn't add anything to handle it given it is possibly not common and the indicator for required user input might be different for other systems. The other option available to you is to use onCommandProcessing check to catch the prompt and provide the required key press. I might put something in the readme under trouble shooting so the possibility of command paging is identified.
Cheers for the feedback
Andrew
I ran into this same issue on some Huawei gear. The following resolved it:
return this.standardPromt = new RegExp("[" + this.sshObj.standardPrompt + "]\s?$");
Add ? to the regular expression this should now be fixed
Thanks! On 11 Feb 2016 12:25 p.m., "Andrew McMurtrie" notifications@github.com wrote:
Add ? to the regular expression this should now be fixed
— Reply to this email directly or view it on GitHub https://github.com/cmp-202/ssh2shell/issues/18#issuecomment-182633075.
Hi,
I have problem with the following code. It seems that commands aren't sended, see commandProcessing event, command isn't passed. Whole test ends on "Command timed out after 5 seconds" (5s is enough) but also in commandTimeout event the command parametr is empty.
I really don't understand, I tried change
standardPrompt: "E1>"
but no change.Code
Result