0

More precisely, the variables in the script are not returned to the calling php script

First the call:

$CPUTemp = exec("/usr/local/sbin/supermon/get_temp");
print "   [ $CPUTemp]";

Now the bash script:

echo -n "CPU: "

CTEMP=$(/opt/vc/bin/vcgencmd measure_temp)
CTEMP=${CTEMP:5}
SAVE=$IFS; IFS="'"; set -- $CTEMP; IFS=$SAVE
CTEMP=$1; FTEMP=$(echo 9 '*' $CTEMP / 5 + 32 | /usr/bin/bc)

if [ "$FTEMP" -le "120" ]; then
echo -en "<span style=\"background-color: palegreen;\">"
elif [ "$FTEMP" -le "150" ]; then
echo -en "<span style=\"background-color: yellow;\">"
else
echo -en "<span style=\"font-weight: bold; color: yellow; background-color: red;\">"
fi

echo -en "&nbsp;${FTEMP}&deg;F, ${CTEMP}&deg;C </span>&nbsp; @ `date +%H:%M`&nbsp;"

If called from command line:

root@myhost:~#  /usr/local/sbin/supermon/get_temp
CPU: <span style="background-color: palegreen;">&nbsp;88&deg;F, 31.6&deg;C </span>&nbsp; @ 08:07&nbsp;

root@myhost:~#

This is what is displayed in browser This is what is displayed in browser

13
  • Does this answer your question? getting output and exit status from shell_exec() Commented Aug 20, 2021 at 18:26
  • 1
    So it looks like it's accessing the bash script and returning something, so that part is working. Perhaps the user the web browser is running under does not have permissions for /opt/vc/bin/vcgencmd measure_temp? Commented Aug 20, 2021 at 18:28
  • Thanks for the edit (still a newbie here). but some of the bash script echo statements are being returned and vcgencmd is executable by the world. Just the variable parameters appear not to be Commented Aug 20, 2021 at 18:29
  • The script is undoubtedly trying to tell you what's wrong. You can find the error messages in your web server logs, or you can add exec 2>>/tmp/mylog.txt early in your script, refresh the page, and then look at the error messages in /tmp/mylog.txt Commented Aug 20, 2021 at 18:35
  • Put exec 2>>/tmp/mylog.txt in right after the variable assignment block in the code and no file is created in /tmp. Nothing in apache2 error log either Commented Aug 20, 2021 at 18:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.