[英]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.