1

我有一个执行期望脚本的 php 脚本。Expect scipt 通过 telnet 远程连接到另一台设备,在那里执行几个命令并返回结果。php脚本只是将远程设备返回的结果输出到网页上的一种方式。

这是我遇到问题的一行:

stty rows 1000

当我从控制台执行我的脚本时,一切正常:远程设备返回 1000 行(或者我在 stty 行中指定的任何内容)输出行。当我从 Web 浏览器执行脚本时,无论我在 stty 行中指定什么,我都会得到 15 行输出。有谁知道我做错了什么?

以防万一,这里是我正在使用的 scipts:

脚本.php

<?php echo shell_exec("/path/to/expect_scipt.exp"); ?>

expect_scipt.exp

#!/usr/bin/expect

stty rows 1000
spawn telnet 10.0.0.1
expect "login:"
send "admin\n"
expect "assword:"
send "admin\n"
expect ">"
send "en\n"
expect "assword:"
send "admin\n"
expect "#"
send "show cable modem\n"
expect "#"
exit

这是我测试它们的方法:

我在控制台中运行它:

#su apache
$php script.php
...1000 lines of output...

我打开我的网络浏览器并导航到 script.php

...15 lines of output...

提前致谢。

4

1 回答 1

1

我在尝试使用 PHP 执行 stty 命令时遇到了类似的问题。

问题是 apache 用户(www-data)没有权限在那些 /dev/ttyX 特殊文件上执行 stty。

要解决它,请编辑 /etc/group 并将用户 www-data 添加到拨出组,这是这些文件的默认组。

希望这可以帮助。

塞巴斯蒂安

于 2012-03-28T14:45:49.213 回答