I'm having problems to write in the file with my CGI.
I make a simple HTML formular to press a button and write a phrase in the .txt file, but it doesn't work.
The server is an Apache2.
The scrips works if executed in the terminal.
ps. The final line of CGI works, updating a HTML page URL.
file 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>
file 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>'
The cgi permissions below
if/elseblock is being accessed, because the value of"$CONTENT"is not what you think it is. Addprintf "CONTENT=${CONTENT}XXX\n" before theif` tests to be sure you CONTENT is as expected. Good luck.echo "<body><pre>$CONTENT</pre></body>"