I'm having trouble with this "show version" command on the cisco router, I need to advance to the next screen by pressing a key when "--show more--" appears. Follow the code:
function showVersion($ssh, $ansi){
$ssh->enablePTY();
$ssh->write("show version\n");
//$ssh->exec("show version");
$prompt_saida = "";
$ssh->setTimeout(3);
$prompt_temp = $ssh->read('#--More--|\[>\]#', NET_SSH2_READ_REGEX);
$prompt_saida = $prompt_temp;
$ssh->setTimeout(3);
while($prompt_temp = $ssh->read('#--More--|\[>\]#', NET_SSH2_READ_REGEX)){
$ssh->setTimeout(3);
$prompt_saida.= $ssh->read(NET_SSH2_READ_REGEX);
if (!preg_match('#--More--$#', $prompt)) { break; }
$ssh->write(' ');
$ssh->setTimeout(3);
}
return $prompt_saida;
//$ssh->write("terminal length 0\n");
//$ssh->write("\n");
$ssh->setTimeout(3);
//$ssh->read();
//$ssh->getLog();
$ansi->appendString($ssh->read());
}
Last login: Wed Oct 4 15:41:46 2017 from xx.xx.xxx.xxx
Restricted access to authorized users. [xxxxxxxxxx[xxx@[34;1mPRA-xxxxxxxx[xxxx> [xxx
Authenticated Successfully!
"DO NOT FORGET SAVE ROUTER CONFIGURATION ON NVRAM, AFTER CONSOLIDATING THE ALTERATIONS !!"
xxxxx_xxxx_xx>show version bash: show: command not found [xxxxxxxxxx[xxx@[34;1mPRA-xxxxxxxx[xxxx> [xxx
with $ssh->exec("show version");
Last login: Wed Oct 4 15:41:46 2017 from xx.xx.xxx.xxx
Restricted access to authorized users. [xxxxxxxxxx[xxx@[34;1mPRA-xxxxxxxx[xxxx> [xxx
Authenticated Successfully!
"DO NOT FORGET SAVE ROUTER CONFIGURATION ON NVRAM, AFTER CONSOLIDATING THE ALTERATIONS !!"
xxxxx_xxxx_xx>/bin/bash: show: command not found
Would you help me ? I'll be very grateful !
I would also like to know the best way to show the router log on screen:
$ssh->read();
$ssh->read(NET_SSH2_READ_REGEX);
$ssh->getLog();
$ansi->getScreen();
thank you
I need to advance to the next screen by pressing a key when "--show more--" appears.
The code is looking for "--More--" - not "--show more--". Maybe that's what you meant?
Also, you're doing $prompt_saida.= $ssh->read(NET_SSH2_READ_REGEX);
. Maybe try doing $prompt_saida.= $ssh->read();
instead. As is you're basically waiting for the number 2 (since NET_SSH2_READ_REGEX is defined by define('NET_SSH2_READ_REGEX', 2);
to show up and 2 doesn't equal --More-- so it might result in the break
being called prematurely.
xxxxx_xxxx_xx>/bin/bash: show: command not found
The fact that you're getting that makes me wonder if you're actually able to do "show version" even with an SSH client like PuTTY or OpenSSH. If not then this problem has nothing to do with phpseclib and discussing it is likely going to distract you from the Cisco IOS (?) experts who could help you. ie. they probably stopped reading after they saw all the PHP code.
I would also like to know the best way to show the router log on screen:
I guess that'd depend on how you define best but, as previously noted, $ssh->read(NET_SSH2_READ_REGEX)
doesn't do what you seem to think it does. $ssh->read('#pattern#', NET_SSH2_READ_REGEX)
does but not $ssh->read(NET_SSH2_READ_REGEX)
.
$ssh->getLog()
only does stuff if you have logging enabled (eg. define('NET_SSH2_LOGGING', 2)
). It also shows unencrypted SSH packets, from key exchange to the opening of the channel, etc. This probably isn't what you're wanting.
As for $ansi->getScreen()
... that could work if you don't like the ANSI codes in your output. And you do have some. eg. [xxxxxxxxxx[xxx@[34;1mPRA-xxxxxxxx[xxxx>
- that @[34;1m
bit is ANSI.
Might also be worth it to play around with $ansi->getHistory()
.