|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2021-04-03 08:02 UTC] benjamin dot lugger at gmail dot com
[2021-04-03 08:03 UTC] rtrtrtrtrt at dfdfdfdf dot dfd
[2021-04-03 08:08 UTC] rtrtrtrtrt at dfdfdfdf dot dfd
[2021-04-03 08:21 UTC] benjamin dot lugger at gmail dot com
[2021-04-03 08:22 UTC] benjamin dot lugger at gmail dot com
-Summary: None
+Summary: Reqex data do not get stored into $match[0]
[2021-04-03 08:22 UTC] benjamin dot lugger at gmail dot com
[2021-04-03 08:25 UTC] benjamin dot lugger at gmail dot com
-Package: *Regular Expressions
+Package: expect
[2021-04-03 08:25 UTC] benjamin dot lugger at gmail dot com
[2021-04-03 19:32 UTC] requinix@php.net
-Status: Open
+Status: Feedback
[2021-04-03 19:32 UTC] requinix@php.net
[2021-04-11 04:22 UTC] pecl-dev at lists dot php dot net
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 15:00:02 2025 UTC |
Description: ------------ The script is used to access a router using SSH. This works fine. It is also possible to issue commands on the router. But it is not possible to get the information into the variable $match[0]. I have installed the latest pecl release on a Pi as well on other Ubuntos running PHP7. The problem seems to be related to php7. I did not change the php.ini. The installation was simple doing the following commands on a PI. sudo apt-get -y install php-pecl-http sudo apt-get -y install php-pear sudo pecl channel-update pecl.php.net sudo apt-get -y install tcl tcl-expect tcl-expect-dev php-dev tcl-dev expect-dev sudo pecl install expect I also added the entry for the expect.so in the php.ini. Otherwise the script would not work at all. As mentioned, the scrip can access the router and issue commands. This can be seen when setting "ini_set ("expect.loguser", "On");". For whatever reason the script is not able to store the regexpt :-) data in $match[0]. Test script: --------------- <?php $username = 'username; $password = 'password'; $testip = 'ipaddress'; define('PASSWORD', 'PASSWORD'); define('ENABLE', 'ENABLE'); define('YESNO', 'YESNO'); define('CONFIRM', 'CONFIRM'); define('SHELL', 'SHELL'); ini_set ("expect.loguser", "Off"); ini_set ("expect.match_max", 10000000); ini_set ("expect.timeout", 120); $stream = expect_popen ("ssh -c aes256-cbc -oKexAlgorithms=+diffie-hellman-group1-sha1 ".$username."@".$testip); $command01 = ''; while (true) { switch (expect_expectl ($stream, array ( array ("assword:", PASSWORD), // SSH is asking for password array (">", ENABLE, EXP_EXACT), // ENABLE array ("yes/no)?", YESNO), // SSH is asking whether to store the host entry array ("confirm", CONFIRM), // SSH is asking whether to store the host entry array (".*#", SHELL, EXP_REGEXP), // Command Prompt ), $match)) { # Case Password case PASSWORD: fputs ($stream, $password."\n"); break; # Case Password Yes/No case YESNO: fputs ($stream, "yes"."\n"); break; # Case CLI Commands case SHELL: if ($command01 == '') { fputs ($stream, "term len 0"."\n"); $command01 = 'done'; sleep(1); break; } else { $show = sendCommand($stream, "show clock"); print "OUTPUT:\n$show\n"; $show = sendCommand($stream, "logout"); break 2; } # Case case EXP_TIMEOUT: # Case case EXP_EOF: break 2; default: die ("Error has occurred!"); } } fclose ($stream); function sendCommand($mystream, $mycommand) { fputs ($mystream, $mycommand."\n"); switch (expect_expectl ($mystream, array (array (".*#", SHELL, EXP_REGEXP)), $match)) { case SHELL: return $match[0]; break; } } ?> Expected result: ---------------- TESTSYSTEM1:/home # php ssh2.php OUTPUT: show clock 07:46:12.240 UTC Sat Apr 3 2021 ROUTER# Actual result: -------------- TESTSYSTEM2:/home $ php ssh2.php ROUTER: