Executing expect script from php. Can't get the stty settings right

1.8k Views Asked by At

I've got a php script that executes an expect script. Expect scipt connects remotely over telnet to another device, executes a couple of commands there and returns results. Php script is just a way to output the results returned by the remote device on a web page.

This is a line I have problems with:

stty rows 1000

When I execute my script from console, everything works correctly: remote device returns 1000 (o whatever I specify in stty rows) lines of output. When I execute my script from web browser, I get 15 lines of output no matter what I specify in stty rows. Does anyone knows what am I doing wrong?

Just in case, here are the scipts I'm using:

script.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

Here is what I do to test them:

I run this in console:

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

I open my web browser and navigate to script.php

...15 lines of output...

Thanks in advance.

1

There are 1 best solutions below

0
On

I had a similar problem trying to execute stty command with PHP.

The problem is that the apache user (www-data) doesnt have permissions to execute stty on those /dev/ttyX special files.

To solve it, edit /etc/group and add the user www-data to the dialout group, which is the default group for those files.

Hope this helps.

Sebastian