I am running a simple PHP script which calls a Python script using exec()
in PHP to activate GPIO pins on a Raspberry Pi to turn (or keep) a light on or off. The script is called by cron every 5 minutes. It works fine, but writes an empty file with the same name as the script each time the script is run. The key part of the script is:
$command = "sudo python lights.py 0"; $result = shell_exec($command);
I have tried it like this:
$command = "sudo python lights.py 1"; $result = exec($command);
And I have tried it with or without echo $result
. In all cases I get the empty file written to the /home/pi
directory. The script is run in /var/www/working directory
.
The cron script is
*/5 * * * * /usr/bin/wget [lan_address]/working/lampRoutine.php >> dev/null 2>&1
Can anyone help?
I have found a solution. The problem was with the cron script. If I add the argument '-O' to the wget command I get no empty file.
wget -O - https://[lanAddress]/path/To/Script >> /dev/null 2>&1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.