So I have on my raspberry pi an website. On this website I have an file "PiConfig.php".
In this file "PiConfig.php" I have this code written:
Code:
$myfile = fopen("/var/www/html/AdminPanel/State.txt", "w") or die("Unable to open file2!");
$txt = 1;
fwrite($myfile, $txt);
fclose($myfile);
On my raspbery pi I have configured an cronjob, which executes every minute this script "test.sh"
In this file "test.sh" I habe this code written:
Code:
#!/bin/bash
State="none2"
input="/var/www/html/AdminPanel/State.txt"
while IFS= read -r var
do
State="$var"
done < "$input"
echo "$State"
MY PROBLEM:
When I create this file "/var/www/html/AdminPanel/State.txt" on my linux machine by a commande (for example with "touch") and I try to execute my script "test.sh" then it echos "1" which I want! But if I call my "PiConfig.php" on my webbrowser and it writes the value "1" inside the "/var/www/html/AdminPanel/State.txt" file, which is still fine. But the problem now is, when I execute my "test.sh" it doesn't echo "1" but "none2" which means it doesn't have read the content out of the file.. Always when PHP writes into the file, my bash code can't read out of it. I tryed everything to change with the user and group "rights" but nothing works. Pleaseeee help <3
These are permissions before the PHP script writes into the textfile.
-rw-r--rw- 1 pi pi State.txt
These are the permissions after I execute the PHP script "PiConfig.php".
-rw-r--rw- 1 pi pi State.txt
The permissions do not change.
When I now edit the textfile "State.txt" with the command "nano" and then I try to run my bash script "test.sh" the script runs like it should and it echos "1".
When I now try to run the PHP file on my webbrowser "PiConfig.php" and then I try ro run my bash script "test.sh" the script does not run like it should because it echos "none2". (Which means the bash script could't read out the file "State.txt" after the PHP script wrote into it.