[英]running bash script from php
當我在Linux機器上運行它(bash腳本)從CMD我上網的輸出,但是當我從其他機器的瀏覽器遠程運行它,我作為輸出下線 。 我的bash腳本:
#!/bin/bash
wget -q --tries=10 --timeout=10 --spider http://google.com
if [[ $? -eq 0 ]]; then
echo "online"
else
echo "offline"
fi
我的PHP腳本是:
<!DOCTYPE html>
<html><head><title>
This is the title
</title></head>
<body>
<?php
$output=shell_exec('/home/pi/checkonline.sh');
echo $output;
?>
</body></html>
注意:我在運行raspbian OS,php5,apache2的raspberry pi 2上托管web服務器。 我使用proxyserver連接到互聯網,我已經在apt.conf中成功配置它以及導出http_proxy,所以這不會是問題。
嘗試使用wget的完整路徑
WGET=/usr/bin/wget
WGET='which wget'
< - 使用反引號
嘗試將您的腳本放在與php腳本相同的文件夾中,並添加執行權限。 至於我,它在線工作和打印。 sudo chmod +x checkonline.sh
<!DOCTYPE html>
<html><head><title>
This is the title
</title></head>
<body>
<h1>output</h1>
<?php
$output=shell_exec('./checkonline.sh');
echo $output;
?>
</body></html>
#!/bin/bash
wget -q --tries=10 --timeout=10 --spider http://www.google.com
if [[ $? -eq 0 ]]; then
echo "online"
else
echo "offline"
fi
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.