2013-05-09 120 views
0

我想从我的机器打开远程机器浏览器。我已经设置了无密码连接(考虑到两个系统都是相同的n/w并且是可信的)。从PHP调用shell脚本没有按预期工作

我能够在下面的脚本运行来启动浏览器,这3个参数

一)。用户名
b)。远程机器的IP地址
c)。 url在Firefox中打开

如果我在我的bash shell中运行这个脚本,我可以打开浏览器而没有任何问题。但是如果我在PHP中调用这个,我无法在远程机器上启动浏览器......它显示所有调试打印,但打开浏览器失败。任何指针都非常有帮助。

下面是我的shell脚本在远程机器上打开浏览器。

#!/bin/bash 
if test $# != 3; 
then 
    echo " 
     $0 
     This command line script is used to launch, browser remotely. You need to pass 3 arguments to this script. 
     YOU NEED TO PASS 3 ARGUMEMTS TO THIS SCRIPT, 
     For example , \$> sh $0 \"<userNameofRemoteSystem>\" \"<remoteSystemIP>\" \"<webPageAddress>\" 

     \$> sh $0 \"Uname\" \"172.17.64.94\" \"mail.google.com\" \n"; 
     exit 1 
fi 

echo "<br><br>\nRECEIVED PARAMETERS,\n\tuserName\t-> |$1|\n\tipAddress\t-> |$2|\n\twebURL\t\t-> |$3|\n\n<br>"; 
echo "<br>Checking if Connection to |$2| WITH USERNAME |$1| is password less???<br><br>"; 
sleep 2 

echo "<br>grep -wc $1 /home/user/.ssh/authorized_keys<br>"; 
count=`grep -wc $1 /home/user/.ssh/authorized_keys`; 
echo "<br>got process count=|$count|<br>" 

sleep 2 

if [ "$count" != 1 ]; 
then 
    echo " 
     Looks like password less connection to |$2| is not configured with this server for username |$1|.. 
     Please congfigure the same and run this script again...\n"; 
fi 

echo "SUCCESSFULLY CONNECTED, LAUNCHING BROWSER ON |$2| WITH |$3|\n"; 
ssh [email protected]$2 "nohup sh openBrowser.sh $3" & 
PID=$$; 
echo "PID IS |$PID|\n"; 
sleep 2; 
echo "<br>PROCESS OUTPUT LOOKS LIKE THIS"; 
ps aux | grep $PID | grep -v grep 
echo "<br>"; 
echo "after sleep"; 
kill -9 $PID && echo "after kill pid=$PID, passed ssh [email protected]$2 \"nohup sh openBrowser.sh $3\" &"; 

下面是我用来调用shell脚本的php脚本。

<?php 
    $c_url=$_POST['url']; 
    $c_name=$_POST['uname']; 
    $c_ip=$_POST['ipaddress']; 

    $output = system("/bin/sh /home/user/launchBrowser_remote.sh $uName $ipADDR $c_url"); 
    echo "$output"; 
?> 

貌似我得到错误的PID内部shell脚本和其杀死来电脚本,而不是启动SSH远程..... BTW我曾经尝试都execshell_exec,但没有运气。

任何指针是很大的帮助

感谢

回答

0

确保在运行PHP文件(Web服务器用户如果被称为在这方面)的用户设置了密码的认证为好。

+0

感谢您的回复。是的,Web服务器没有密码连接,这解决了这个问题。再次感谢。 – cb24 2013-05-10 04:48:08