[英]CGI (shell script) not write in the file with echo command
我在用我的 CGI 寫入文件時遇到問題。
我做了一個簡單的 HTML 公式來按下一個按鈕並在 .txt 文件中寫一個短語,但它不起作用。
服務器是Apache2。
如果在終端中執行,腳本就可以工作。
附: CGI 的最后一行工作,更新 HTML 頁面 URL。
文件 index.html
<html>
<title>BeagleBone</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<body>
<div class="w3-container w3-green">
<h1>BeagleBone GPIO Control</h1>
<p>Acesso remoto a GPIO's em rede local</p>
</div>
<div class="w3-row-padding">
<div class="w3-third">
<h2>GPIO x</h2>
<p>Led blue</p>
<form method="POST" action="/cgi-bin/led.cgi">
<input type="submit" name="led" value="ON">
<input type="submit" name="led" value="OFF">
</form>
</div>
</body>
</html>
led.gci 文件
#!/bin/bash
LED_FILE="/home/gpcosta/Desktop/data.txt"
read CONTENT
if [ "$CONTENT" == "led=ON" ]; then
echo "Apertou botao ON" >> $LED_FILE
elif [ "$CONTENT" == "led=OFF" ]; then
echo "Apertou botao OFF" >> $LED_FILE
fi
echo "Content-type: text/html"
echo ""
echo '<html>'
echo '<meta http-equiv="refresh" CONTENT="0;url=http://192.168.15.20/index.html">'
echo '</html>'
下面的 cgi 權限
這是因為 Web 服務器對該目錄沒有權限。
要解決此問題,請在您的 cgi 服務器上運行以下腳本:
echo “content-type: text/html”
echo “”
echo “<html>
<head>
<meta charset='utf-8'/>
<title>What permission?</title>
</head>
<body>
<p>Run this on your server terminal:</p>
<pre>chown $(whoami) ${PWD}
chmod 755 ${PWD}</pre>
</body>
</html>”
然后只需復制您的 Web 瀏覽器將顯示的腳本並將其粘貼到 CGI 服務器終端上,請記住使用特權用戶運行它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.