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我曾經嘗試都exec
和shell_exec
,但沒有運氣。
任何指針是很大的幫助
感謝
感謝您的回覆。是的,Web服務器沒有密碼連接,這解決了這個問題。再次感謝。 – cb24 2013-05-10 04:48:08