I am trying to get the following script to execute properly via PHP exec. It works fine in the Linux terminal (returning the average CPU core temperature):
sensors | perl -ne 'if (/^Core \d+:\s+\+(.*?)°C/) { $s += $1; $c++; } END { printf("%.1fC", $s/$c) }'
I have tried to escape the double quotes, but realize there may be another issue. I am using the script in PHP like this:
exec("sensors | perl -ne 'if (/^Core \d+:\s+\+(.*?)°C/) { $s += $1; $c++; } END { printf("%.1fC", $s/$c) }'", $results);
echo $results;
EDIT: escapeshellcmd is probably the right direction, but I am having trouble seeing how to implement it.