2011-11-12 47 views
1

我有一個執行期望腳本的php腳本。希望scipt通過telnet遠程連接到另一個設備,在那裏執行一些命令並返回結果。 PHP腳本只是一種輸出遠程設備在網頁上返回的結果的方法。從php執行expect腳本。無法獲得stty設置

這是一條線我有問題:

stty rows 1000 

當我執行從控制檯我的劇本,一切正常:遠程設備返回1000(鄰不管我的stty行指定)的輸出線。 當我從Web瀏覽器執行我的腳本時,無論我在stty行中指定什麼,我都會得到15行輸出。 有誰知道我做錯了什麼?

以防萬一,這裏是我使用的scipts:

的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 

這裏是什麼我確實要測試它們:

我在控制檯運行如下命令:

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

我打開網頁瀏覽器,瀏覽到的script.php

...15 lines of output... 

在此先感謝。

回答

1

我有一個類似的問題試圖用PHP執行stty命令。

問題是apache用戶(www-data)沒有權限在這些/ dev/ttyX特殊文件上執行stty。

編輯/ etc/group並將用戶www-data添加到撥出組(這是這些文件的默認組)。

希望這會有所幫助。

塞巴斯蒂安